This project implements a simple API just to illustrate how one would go about implementing a REST API using Actix Web and Rust.
source configure.sh
cargo run
# or
cargo watch -x check -x run
# or
./watch.sh
Browse the docs and test the API via the Swagger UI:
open http://localhost:8001/docs
Browse the docs using Redoc. This is an alternative to the Swagger UI:
open http://localhost:8001/redoc
Configure project:
source configure.sh
Open the project in Visual Studio Code:
code .
Run rustfmt
formatter:
# check
cargo fmt --all -- --check
# fix
cargo fmt --all
Run clippy
linter:
# check
cargo clippy -- --deny warnings
# fix
cargo clippy --fix
Run tests:
cargo test
Generate test coverage report:
./coverage.sh
# or
cargo tarpaulin --skip-clean --ignore-tests --out Html --output-dir coverage
# open coverage report
open coverage/tarpaulin-report.html
cargo build
Setup DB migrations:
diesel setup
Generate a new DB migration:
diesel migration generate create_books
Apply DB migrations:
diesel migration run
In order to do this you will need Podman. See Setup Podman on macOS for details.
Rebuild container image and start container:
./scripts/podman.sh
Delete container and image:
./scripts/podman-delete.sh
# create new project
cargo init
# add packages
cargo add actix-web dotenv
cargo add diesel --features sqlite,r2d2
cargo add serde --features derive
cargo add serde_json
cargo add chrono --features serde
cargo add utoipa --features actix_extras
cargo add utoipa-swagger-ui --features actix-web
cargo add diesel_migrations
Install tools :
# Diesel CLI
cargo install diesel_cli --no-default-features --features sqlite
# Watch
cargo install cargo-watch
# Test Coverage
cargo install cargo-tarpaulin