This project implements a CRUD (Create, Read, Update, Delete) API in Rust using Actix-web framework and PostgreSQL as the database. The API allows users to perform CRUD operations on a resource (e.g., users, products, etc.).
- Create, Read, Update, and Delete operations on a resource.
- Secure endpoints with JWT (JSON Web Tokens) authentication.
- Utilizes asynchronous programming with Tokio runtime.
- Database integration with PostgreSQL using the
sqlx
crate. - Dockerized deployment for easy scaling and management.
- Rust programming language (https://www.rust-lang.org/)
- Docker (https://www.docker.com/)
- Docker Compose (https://docs.docker.com/compose/)
- Clone the repository:
git clone https://github.com/your_username/rust-api.git
cd rust-api
- Install dependencies:
cargo build
- Set up the PostgreSQL database. You can use Docker Compose to run a PostgreSQL container:
docker-compose up -d postgres
- Run database migrations to create tables:
cargo run --bin migrations
- Start the API server:
cargo run --bin api
The API server will start on http://localhost:8080.
GET /resource
: Retrieve all resources.GET /resource/{id}
: Retrieve a specific resource by ID.POST /resource
: Create a new resource.PUT /resource/{id}
: Update a resource by ID.DELETE /resource/{id}
: Delete a resource by ID.
To deploy the application using Docker, follow these steps:
- Build the Docker image:
docker build -t rust-api .
- Run the Docker container:
docker run -d --name rust-api -p 8080:8080 rust-api
The API will be accessible at http://localhost:8080.
Contributions are welcome! Feel free to open an issue or submit a pull request for any improvements or additional features.
This project is licensed under the MIT License - see the LICENSE file for details.