A fast, modular, and efficient RESTful API built with the Rocket web framework in Rust π.
rest_rocket is a lightweight and scalable RESTful API designed to serve as a foundation for modern web applications and microservices. Built using the powerful Rocket framework, it emphasizes performance, security, and developer experience.
β
Built on Rocket 0.5+
β
Modular architecture
β
Type-safe request and response handling
β
JSON support (via serde)
β
Centralized error handling
β
Easy-to-extend endpoints
β
Environment-based configuration
β
Ready for production deployment
- Rust (version 1.70+ recommended)
cargopackage manager (comes with Rust)
git clone https://github.com/yourusername/rest_rocket.git
cd rest_rocketcargo build --releasecargo runThe server will start on http://localhost:8000 by default.
Hereβs a quick overview of the available REST endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome message |
| GET | /api/v1/items |
List all items |
| GET | /api/v1/items/<id> |
Get item by ID |
| POST | /api/v1/items |
Create a new item |
| PUT | /api/v1/items/<id> |
Update an item |
| DELETE | /api/v1/items/<id> |
Delete an item |
curl http://localhost:8000/api/v1/itemsResponse:
[
{
"id": 1,
"name": "Example Item",
"description": "This is an example."
}
]rest_rocket/
βββ src/
β βββ main.rs # Application entry point
β βββ routes.rs # API route definitions
β βββ models.rs # Data models and types
β βββ handlers.rs # Request handlers
β βββ errors.rs # Custom error handling
β βββ config.rs # Configuration loading
βββ Cargo.toml
βββ README.md
Run all tests using:
cargo testTo run the app in development with auto-reloading, use:
cargo install cargo-watch
cargo watch -x run- Input validation using
serdeand custom types - Centralized error handling to avoid leaking sensitive information
- CORS support can be added easily
- TLS and authentication can be integrated if needed
Contributions are welcome! To contribute:
- Fork this repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -m 'Add your feature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
Please make sure to follow the Rust API Guidelines.
This project is licensed under the MIT License. See the LICENSE file for details.
Made with β€οΈ using Rust and Rocket.
---
β
If youβd like, I can help you generate the initial code structure (`main.rs`, `routes.rs`, etc.) too.