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.
- rust and cargo installed if using local deployment
- docker installed if using docker deployment
Exposes CRUD functionality for resource
:
GET /resource
retrieve allresource
objectsPOST /resource
save aresource
on the databaseGET /resource/{id}
retrieve aresource
by idPUT /resource/{id}
update aresource
by idDELETE /resource/{id}
delete aresource
by id
POST
and PUT
requests require the body to look like the following:
{
"some_key_1": "a",
"some_key_2": "b",
"some_key_3": "c"
}
- start a
mongod
deamon locally (mongodb://localhost:27017
)- set environment variables
MONGO_HOST
andMONGO_PORT
the appropriate values OR change the dynamicmongo_connection_string
indb.rs
to a non dynamic value - set environment variable
PORT
to appropriate value OR change the dynamicbinding_address
inmain.rs
to a non dynamic value
- set environment variables
- run
cargo build --release
- run
./target/release/actix-mongodb-boilerplate
- run
docker-compose up --build
Feel free to contribute, you may want to add extra endpoints, benchmarks, performance or quality of life enhancements, etc.