2 releases
0.1.1 | May 4, 2023 |
---|---|
0.1.0 | Mar 10, 2023 |
#26 in #practice
13KB
244 lines
Jast
Install
Cargo.toml
[dependencies]
jast_lib = "0.1.1"
Example
use jast_lib::{Http, Res, DataTypes, RouteResponse, Builder};
fn main() {
fn controller() -> RouteResponse<'static> {
let response = RouteResponse {
method: "GET",
res: Res::json(vec![
("name", DataTypes::Str(String::from("Juan"))),
("lastname", DataTypes::Str(String::from("Alberto"))),
("id", DataTypes::Int(i32::from(1)))
])
};
response
}
let routes = vec![
Http::route("/", controller()),
Http::route("/hola",
(|| RouteResponse { method: "GET", res: Res::json(vec![("name", DataTypes::Str("Juan".to_string()))]) })()),
Http::route("/html",
(|| RouteResponse { method: "GET", res: "src/index.html"})())
];
let settings = Builder::new("localhost:8080", routes).worker_threads(4);
Http::create_server(
settings
)
}
Dependencies
~1.3–2MB
~36K SLoC