1 unstable release
Uses new Rust 2024
new 0.1.9 | Apr 17, 2025 |
---|---|
0.1.8 |
|
#42 in #rate-limiting
788 downloads per month
32KB
239 lines
Rusty API
Rusty API is a secure and lightweight Rust library for building backend APIs. It features HTTPS, password-protected routes, rate limiting, and more, making it ideal for rapid API development.
Features
- Password-Protected Routes: Easily secure specific routes with passwords.
- HTTPS Support: Built-in support for secure communication using Rustls.
- Rate Limiting: Prevent abuse with configurable rate limits.
- CORS Configuration: Flexible CORS settings for cross-origin requests.
- Actix Web Integration: Built on top of Actix Web for high performance.
Installation
Add rusty-api
to your Cargo.toml
:
[dependencies]
rusty-api = "0.1.8"
Usage
Setting Up Your API
Here's an example of how to use rusty-api to create an API with public and password-protected routes:
use rusty_api;
async fn password_route(_req: rusty_api::HttpRequest) -> rusty_api::HttpResponse {
rusty_api::HttpResponse::Ok().body("Password route accessed!")
}
async fn open_route(_req: rusty_api::HttpRequest) -> rusty_api::HttpResponse {
rusty_api::HttpResponse::Ok().body("Open route accessed!")
}
fn main() {
let routes = rusty_api::Routes::new()
.add_route_with_password("/password_route", password_route, "Password123")
.add_route("/open_route", open_route);
rusty_api::Api::new()
.certs("certs/cert.pem", "certs/key.pem")
.auth_db("users.db")
.rate_limit(3, 20)
.bind("127.0.0.1", 8443)
.configure_routes(routes)
.configure_cors(|| {
rusty_api::Cors::default()
.allow_any_origin()
.allow_any_method()
.allowed_header("ngrok-skip-browser-warning")
})
.start();
}
Generating Self-Signed Certificates
To enable HTTPS, generate self-signed certificates:
mkdir -p certs
openssl req -x509 -newkey rsa:4096 -keyout certs/key.pem -out certs/cert.pem
Running the API
Run your API with:
cargo run
Projects Using This Package
Here are some projects that use rusty-api for their API's. Want to add your project? See Contributing below!
Project | Description | Links |
---|---|---|
ServerWatch | A lightweight system monitoring tool that collects metrics and exposes them via a secure HTTPS endpoint. Built for Raspberry Pi and other Linux systems. | GitHub | Website |
Your Project Here | Have a project using this package? Submit a PR to add it! | See Contributing below! |
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
License
This project is licensed under the MIT License.
Dependencies
~25–37MB
~732K SLoC