Skip to content

Latest commit

 

History

History
104 lines (76 loc) · 2.83 KB

README.md

File metadata and controls

104 lines (76 loc) · 2.83 KB

rust-axum-scylla

Useless, (almost) production-ready demo web application using:

Features:

  • Rest API to create, find and delete vehicles
  • Persistent storage in database

Software Design

Architecture:

architecture image

Libraries/tools:

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:

classdiagram image

Build and run demo app

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

Test (cargo)

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.

Test (curl)

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

Check database

$ docker exec -it hello-scylla nodetool status
$ docker exec -it hello-scylla cqlsh
cqlsh> SELECT * from hello.vehicles;