This Rust project serves as a demonstration of utilizing the SQLx crate to implement a RESTful API with CRUD operations for managing User data.
Before running the project, ensure you have the following installed:
- Rust: Install Rust
- SQLite: For simplicity, this demo uses SQLite as the database. You can install it via your package manager or download it from SQLite website.
-
Clone this repository:
git clone git@github.com:falila/sqlx_demo.git
-
Navigate to the project directory:
cd sqlx_demo
-
Build and run the project:
cargo run
The API provides the following endpoints for managing User data:
-
Create User:
POST /users
-
Get All Users:
GET /users
-
Get User by ID:
GET /users/{id}
-
Update User by ID:
PUT /users/{id}
-
Delete User by ID:
DELETE /users/{id}
-
Create User:
curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","email":"john@example.com"}' http://localhost:8080/users
-
Get All Users:
curl http://localhost:8080/users
-
Get User by ID:
curl http://localhost:8080/users/1
-
Update User by ID:
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Updated Name","email":"updated@example.com"}' http://localhost:8080/users/1
-
Delete User by ID:
curl -X DELETE http://localhost:8080/users/1