1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*!
* [](https://github.com/AlexanderHeffernan/rusty-api)
* [](https://crates.io/crates/rusty-api)
* [](https://docs.rs/rusty-api)
*
* Rusty API is lightweight and secure library for building backend APIs in Rust, designed to simplify the development of modern web services.
*
* Features:
* - **Modular Design**: Oragnized into modules for API logic, routing, and core configurations, making it easy to extend and maintain.
* - **Actix Web Integration**: Built on the Actix Web framework for high-performance and asynchronous web applications.
* - **TLS Support**: Includes utilities for configuring Rustls for secure HTTPS communication.
* - **CORS Handling**: Provides seamless integration with Actix CROS for managing croos-origin requests.
* - **Password Protection**: Offers built-in support for password-protected routes, enhancing security for sensitive endpoints.
*
* Rust API is ideal for developers looking to quickly build secure and scalable APIs with minimal boilerplate.
*
* <br>
*
* ## Installation
* To use rusty-api in your project, add the following to your `Cargo.toml`:
* ```toml
* [dependencies]
* rusty-api = "0.1.8"
* ```
*
* ## Example
* ### Setting up your API
* Here's an example of how to use rusty-api to create an API with public and password-protected routes:
* ```rust,no_run,ignore
* 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")
* .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
* HTTPS requires TLS certificates. You can generate self-signed certificates using OpenSSL:
* ```bash
* mkdir -p certs
* openssl req -x509 -newkey rsa:4096 -keyout certs/key.pem -out certs/cert.pem
* ```
*
* ### Running the API
* To run the API, use the following command:
* ```bash
* cargo run
* ```
*/
pub use crateApi;
pub use crateRoutes;
pub use crateload_rustls_config;
pub use crate;
pub use cratevalidate_token;
pub use crateClaims;
pub use ;
pub use ;
pub use Cors;
use Lazy;
use SqlitePool;
/**
* The `DB_POOL` is a global connection pool for SQLite database.
*
* It is initialized lazily when first accessed, using the `DATABASE_URL`
* environment variable to determine the database location.
*/
pub static DB_POOL: = new;