This project is an asynchronous REST API for managing tickets, built with Rust using the Axum web framework. It demonstrates modern Rust patterns for web development, including async/await, state management, error handling, and modular design.
- Create Ticket: Add new tickets with a title and description.
- Retrieve Ticket: Get details of a specific ticket by its ID.
- Patch Ticket: Update the title, description, or status of an existing ticket.
- List Tickets: Retrieve all tickets in the system.
- Health Check: Simple endpoint to verify the service is running.
- 📚 Learning Guide - Comprehensive guide covering Rust async patterns, architecture analysis, and learning exercises
- 🏗️ Architecture Overview - High-level system design and module interactions
The application follows a layered architecture pattern:
Diagram created with Excalidraw
data.rs
: Defines core data structures for tickets, including types for ticket ID, title, description, status, and request/response payloads. Handles validation logic for input fields.store.rs
: Implements an in-memory, thread-safe ticket store usingtokio::sync::RwLock
andArc
. Provides async methods to add, retrieve, patch, and list tickets. Custom error types for not found and invalid fields.handlers.rs
: Contains Axum route handlers for each API endpoint. Handles request parsing, validation, error responses, and calls into the store.lib.rs
: Re-exports modules for easy access and sets up the public API for the crate.main.rs
: Sets up the Axum router, configures CORS, initializes tracing, and starts the HTTP server. Prints available endpoints and example usage.
Method | Path | Description |
---|---|---|
GET | /health |
Health check |
POST | /tickets |
Create a new ticket |
GET | /tickets |
List all tickets |
GET | /tickets/:id |
Get a specific ticket |
PATCH | /tickets/:id |
Update a specific ticket |
Create a ticket:
curl -X POST http://localhost:3000/tickets \
-H 'Content-Type: application/json' \
-d '{"title":"Fix bug","description":"Fix the critical bug in the system"}'
- Install Rust (https://rustup.rs/)
- Clone the repository
- Run the server:
cargo run
- The API will be available at
http://localhost:3000