Restify
Restify is a powerful Rust framework designed to streamline the process of building web servers, offering support for multiple web frameworks like Axum, Actix, Rocket (and more in the future), while seamlessly integrating OpenAPI specification generation for effortless API documentation.
Features
- Multi-Framework Support: Build your application using your preferred web framework, currently supporting Axum and with plans for Actix and Rocket integration.
- Declarative Routing: Define routes and controllers using intuitive macros, making your code clean and readable.
- Automatic OpenAPI Generation: Restify automatically generates OpenAPI documentation based on your defined routes and data structures.
- Modular Structure: Organize your application into modules for better maintainability and scalability.
- State Management: Easily manage shared application state.
- Middleware Support: Benefit from the middleware capabilities of your chosen web framework.
Roadmap
- Axum
- Actix
- Rocket
- OpenAPI
Installation
Add the following to your Cargo.toml
file, choosing the feature for your desired web framework:
[]
= { = "0.0.3", = ["axum"] }
# Dependencies for your chosen web framework (example for Axum)
= "0.6"
= { = "1", = ["full"] }
Usage
1. Define your data structures:
// /todo/entities.rs
use Serialize;
// /todo/dto.rs
use Deserialize;
2. Create your service:
// src/todo/service.rs
use HashMap;
use *;
use Uuid;
use crate AppState;
use ;
use ;
3. Create your controller:
// src/todo/controller.rs
use ;
use *;
use TraceLayer;
use ;
4. Define your modules:
/// src/todo/mod.rs
use Module;
;
// src/app.rs
use ;
use *;
use Mutex;
use TraceLayer;
use crate;
;
;
;
6. If you use Axum and have state, you can create a restify.toml file to define the state path, so you don't have to add it in every Module
, Controller
, or Injectable
like #[module(state(AppState))]
# restify.toml
= "crate::app::AppState"
5. Create your application (example for Axum):
use ;
use IntoRouter; // Import specific to Axum
async
Configuration
Restify offers configuration options through the controller
and Module
macros. These options allow you to specify:
- Path: The base path for the controller's routes.
- State: The type of shared application state to inject into the controller (for axum).
- Wrap: Middleware layers to apply to the controller's routes (using the middleware mechanisms of your chosen framework).
Contribution
Contributions are welcome! If you'd like to contribute to Restify, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and write tests.
- Submit a pull request.
License
This project is licensed under the [MIT License][license].
Acknowledgements
- Axum, Actix, Rocket: The supported web frameworks.
- OpenAPI Specification: The standard for defining REST