Small example / boilerplate for a rust REST webserver with actix-web and mongodb
MIT License
Warning
This example is quite old and the libraries are outdated. I packaged this in Docker, so it will still work, but please consider using a more timely example.
A small rust web server example/boilerplate with RESTful CRUD functionality, utilizing actix web and mongdb.
Inspired by mehmetsefabalik/rust-mongodb-example and nintha/demo-myblog.
Exposes CRUD functionality for resource
:
GET /resource
retrieve all resource
objectsPOST /resource
save a resource
on the databaseGET /resource/{id}
retrieve a resource
by idPUT /resource/{id}
update a resource
by idDELETE /resource/{id}
delete a resource
by idPOST
and PUT
requests require the body to look like the following:
{
"some_key_1": "a",
"some_key_2": "b",
"some_key_3": "c"
}
mongod
deamon locally (mongodb://localhost:27017
)
MONGO_HOST
and MONGO_PORT
the appropriate values OR change the dynamic mongo_connection_string
in db.rs
to a non dynamic valuePORT
to appropriate value OR change the dynamic binding_address
in main.rs
to a non dynamic valuecargo build --release
./target/release/actix-mongodb-boilerplate
docker-compose up --build
Feel free to contribute, you may want to add extra endpoints, benchmarks, performance or quality of life enhancements, etc.