Crates.io | dev_api |
lib.rs | dev_api |
version | 0.1.28 |
source | src |
created_at | 2022-05-31 07:54:23.703105 |
updated_at | 2022-11-25 15:01:26.234004 |
description | Web API wrappers on top of actix-web |
homepage | https://github.com/deversify/dev_api |
repository | https://github.com/deversify/dev_api |
max_upload_size | |
id | 597337 |
size | 31,633 |
A set of pre-configured modules for Rust web APIs. Currently in early stage development.
We want to open source how we do backend development in Rust and offer a fast and simple way to get started writing web APIs without locking you in into another custom framework.
Note: given how early stage this project is, the example is not complete. You need to install actix-web and create your own configs and dependencies that you want to inject into app_data.
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dev_api::tracing::init("my-service".to_string()).expect("Failed to initialize tracer.");
// All logs should be wrapped in a span. This is automatically done for each controller.
tracing::info_span!("main:server_starting").in_scope(|| {
tracing::info!("Starting server...");
});
let server = HttpServer::new(move || {
// The configure function must be a ServiceConfig factory function: https://docs.rs/actix-web/latest/actix_web/web/struct.ServiceConfig.html
let configs: Vec<fn(&mut web::ServiceConfig)> = vec![
users::configure,
products::configure
];
// dev_api will mount your services, configure the app, and send the app back so you can extend it further.
let app = dev_api::http::new(configs);
// Extend the app with your own dependencies.
app
.app_data(web::Data::new(jwt.clone()))
.app_data(web::Data::new(users_repo.clone()))
.app_data(web::Data::new(products_repo.clone()))
})
.bind(("0.0.0.0", 8080))?
.run();
tracing::info_span!("main:server_started").in_scope(|| {
tracing::info!("Server started!");
});
server.await
Please look at the source code for more information. src/http.rs
will show how we setup the server app.
When it works, you can verify it by going to localhost:8080
in your browser. You should get back an empty 200 success response in your network tab.