This repository contains a Rust CRUD API project that provides basic CRUD (Create, Read, Update, Delete) operations for managing user data.
Before setting up the project, ensure you have the following prerequisites installed:
- Rust programming language (Installation Guide)
- Docker (Installation Guide)
- Docker Compose (Installation Guide)
-
Clone the project repository:
git clone <repository_url>
-
Navigate to the project directory:
cd <project_directory>
-
Build the Docker image:
docker-compose build
Ensure that you have a PostgreSQL database URL configured. You can set it as an environment variable named DATABASE_URL
. Example:
export DATABASE_URL=postgres://username:password@localhost/database_name
- Endpoint:
POST /users
- Description: Creates a new user with the provided name and email.
- Request Body: JSON object containing
name
andemail
. - Response:
- Status Code: 200 OK if successful.
- Status Code: 500 INTERNAL SERVER ERROR if an error occurs.
- Endpoint:
GET /users/:id
- Description: Retrieves user details by ID.
- Parameters:
id
: ID of the user to retrieve.
- Response:
- Status Code: 200 OK if successful.
- Status Code: 404 NOT FOUND if user with the provided ID does not exist.
- Status Code: 500 INTERNAL SERVER ERROR if an error occurs.
- Endpoint:
GET /users
- Description: Retrieves details of all users.
- Response:
- Status Code: 200 OK if successful.
- Status Code: 500 INTERNAL SERVER ERROR if an error occurs.
- Endpoint:
PUT /users/:id
- Description: Updates the details of the user with the provided ID.
- Parameters:
id
: ID of the user to update.
- Request Body: JSON object containing updated
name
andemail
. - Response:
- Status Code: 200 OK if successful.
- Status Code: 404 NOT FOUND if user with the provided ID does not exist.
- Status Code: 500 INTERNAL SERVER ERROR if an error occurs.
- Endpoint:
DELETE /users/:id
- Description: Deletes the user with the provided ID.
- Parameters:
id
: ID of the user to delete.
- Response:
- Status Code: 200 OK if successful.
- Status Code: 404 NOT FOUND if user with the provided ID does not exist.
- Status Code: 500 INTERNAL SERVER ERROR if an error occurs.
curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","email":"john@example.com"}' http://localhost:8080/users
curl http://localhost:8080/users/1
curl curl http://localhost:8080/users
curl curl -X PUT -H "Content-Type: application/json" -d '{"name":"Jane Doe","email":"jane@example.com"}' http://localhost:8080/users/1
curl curl -X DELETE http://localhost:8080/users/1