The following repository contains an small Rest API example with Rust language. It creates a CRUD for bikes The next image is a simple architecture diagram.
Diesel ORM:
cargo install diesel_cli --no-default-features --features postgres
Auto-reload:
cargo install systemfd cargo-watch
- Deploy the Postgres database
docker-compose up
- Diesel configuration:
export DATABASE_URL=postgres://di:di@localhost/di
diesel setup
diesel migration run
- Start the application:
The following command runs the aplication and allows to reload it when you change something in the code. Please check the
.env
to verified the port in wich it will run the application.
systemfd --no-pid -s http::4000 -- cargo watch -x run
curl --request GET \
--url http://localhost:4000/bikes
curl --request GET \
--url http://localhost:4000/bikes/1fdf0da9-1bfe-410e-b6ac-5a27b3cd1dc8
curl --request POST \
--url http://localhost:4000/bikes \
--header 'content-type: application/json' \
--data '{
"model": "MBT",
"description": "This is a montain bike"
}
'
curl --request PUT \
--url http://localhost:4000/bikes/1fdf0da9-1bfe-410e-b6ac-5a27b3cd1dc8 \
--header 'content-type: application/json' \
--data '{
"model": "",
"description": "",
"created_at": "2020-07-07T02:06:24.028203",
"updated_at": "2020-07-07T02:06:24.028220"
}'
curl --request GET \
--url http://localhost:4000/bikes/1fdf0da9-1bfe-410e-b6ac-5a27b3cd1dc8