Skip to content

This is a practice project for building a Rust API using Actix web framework, Serde for serialization/deserialization, Diesel for database interaction, and PostgreSQL as the database.

Notifications You must be signed in to change notification settings

NashTech-Labs/rust-api-with-actix-diesel

Repository files navigation

Rust API Project with Actix, Serde, Diesel, and PostgreSQL

This is a practice project for building a Rust API using Actix web framework, Serde for serialization/deserialization, Diesel for database interaction, and PostgreSQL as the database.

Prerequisites

Make sure you have the following installed before running the project:

Setup

  1. Clone the repository:

    git clone https://github.com/NashTech-Labs/rust-api-with-actix-diesel.git
  2. Navigate to the project directory:

cd test-api-rust
  1. Build the project using cargo:
cargo build --release
  1. Run the database migrations (you will need to install diesel_cli first):
diesel migration run
  1. Start the server:
cargo run

Project Structure

src/
|-- main.rs         # Application entry point
|-- models/         # Database models
|-- routes/         # API routes and handlers
|-- schema.rs       # Generated by Diesel, represents the database schema
|-- db.rs           # Database initialization and connection
|-- .env.example    # Example environment file
|-- diesel.toml     # Diesel configuration file

API Endpoints

+ `GET /tweets`: Get all tweets.
+ `GET /tweets/{id}`: Get a tweet by ID.
+ `POST /tweets`: Create a new tweet.
+ `DELETE /tweets/{id}`: Delete a tweet by ID.
+ `GET /tweets/{id}/likes`: Get likes on a tweet by ID.
+ `POST /tweets/{id}/like`: Like a tweet by ID.
+ `DELETE /tweets/{id}/like`: Unlike a tweet by ID.
Feel free to use and modify this template according to your project's needs.
If you have any questions or suggestions, please let me know!</s>

Deployed on Docker

docker compose up --build

The APIs will be exposed to port 9090

About

This is a practice project for building a Rust API using Actix web framework, Serde for serialization/deserialization, Diesel for database interaction, and PostgreSQL as the database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published