Useless, (almost) production-ready demo web application using:
Features:
- Rest API to create, find and delete vehicles
- Persistent storage in database
Architecture:
Libraries/tools:
- Web application framework (based on Axum)
- Scylla database with rust driver
- Command line arguments parsing based on argh
- Mocking based on mockall
Continuous integration:
- Github actions, see .github/workflows
- Docker image generation, see Dockerfile
Missing:
- Session/Authentication
- DB migration
- OpenAPI generation
- i18n based on cargo-i18n and the fl! macro
Class diagram:
Directly via cargo (pre-condition: Scylla DB already running)
$ RUST_LOG=hello=debug,tower_http::trace=debug cargo run
Via docker:
$ docker run --name hello-scylla -d -p 9042:9042 scylladb/scylla
$ docker build -t hello-app .
$ docker run -t -i -p 3000:3000 --link=hello-scylla:scylla -it hello-app --addr scylla
Via docker-compose:
$ docker-compose build
$ docker-compose up
All tests:
$ cargo test
Unit tests only:
$ cargo test --lib
Integration tests only:
$ cargo test --test '*' -- --test-threads=1
Note: we need to ensure that the tests are not concurrently executed because it would mess up the checks.
Create vehicle:
$ curl -v -H "Accept: application/json" -H "Content-type: application/json" localhost:3000/vehicle -d '{"vin":"vin1","engine_type":"Combustion"}'
$ curl -v -H "Accept: application/json" -H "Content-type: application/json" localhost:3000/vehicle -d '{"vin":"vin2","engine_type":"Ev", ev_data: {"battery_capacity_in_kwh": 62, "soc_in_percent": 74}}
$ curl -v -H "Accept: application/json" -H "Content-type: application/json" localhost:3000/vehicle -d '{"vin":"vin3","engine_type":"Phev"}'
Find vehicle by vin:
$ curl -v -H "Accept: application/json" localhost:3000/vehicle/vin2 -G
Delete vehicle by vin:
$ curl -v -H "Accept: application/json" -X DELETE localhost:3000/vehicle/vin2 -G
$ docker exec -it hello-scylla nodetool status
$ docker exec -it hello-scylla cqlsh
cqlsh> SELECT * from hello.vehicles;