A near-complete Q&A REST API built with Rust, Warp, Tokio, and Serde—handling questions, answers, votes, and full CRUD operations.
- RESTful endpoints for questions and answers
- Nested answer routes (
/questions/{id}/answers) - Upvoting/downvoting functionality
- In-memory database using
Arc<Mutex<_>> - Fully async with
Tokio - Typed JSON parsing via
Serde
- Rust & Cargo ≥ 1.60
git clone https://github.com/TMottur/rust-warp-api.git
cd rust-warp-api
cargo runServer runs on http://localhost:3030 by default.
You can override this using the PORT environment variable.
-
Get all questions
GET /questions
-
Get a single question
GET /questions/{id}
-
Create a question
POST /questions Content-Type: application/json { "title": "What is Warp?", "body": "How does warp's filter system work?" }
-
Update a question
PUT /questions/{id} Content-Type: application/json { "title": "Updated Title", "body": "Updated body content" }
-
Delete a question
DELETE /questions/{id}
-
Vote
POST /questions/{id}/vote/up POST /questions/{id}/vote/down
-
List all answers to a question
GET /questions/{q_id}/answers
-
Get a single answer
GET /questions/{q_id}/answers/{a_id}
-
Create an answer
POST /questions/{q_id}/answers Content-Type: application/json { "body": "Here's how to use nested filters in Warp..." }
-
Update an answer
PUT /questions/{q_id}/answers/{a_id} Content-Type: application/json { "body": "Updated answer body..." }
-
Delete an answer
DELETE /questions/{q_id}/answers/{a_id}
-
Vote
POST /questions/{q_id}/answers/{a_id}/vote/up POST /questions/{q_id}/answers/{a_id}/vote/down
- In-memory storage:
type Db = Arc<Mutex<DbInner>> - Handlers in
handlers.rs - Routes in
routes.rs - Models in
models.rsusing Serde - Thread-safe state: shared between handlers using
tokio::sync::Mutex