This is just an experimental project to explore building a web service or API in Rust. It uses the powerful Actix Web framework.
Easiest way to spin up a working sample of this repo is via Docker Compose
To spin up the entire stack on local, just run the following command (depending on your target architecture).
- arm64 / aarch64, e.g. M1 Mac,
# It is supported by default. You can simply run
docker-compose up
# You may also specify it explicitly
docker-compose build --build-arg "ARCH=aarch64"
docker-compose up
- amd84 / x86_64, e.g. Intel chips,
# You need to specify the ARCH argument accordingly
docker-compose build --build-arg "ARCH=x86_64"
docker-compose up
You need to have Docker installed on your machine.
The components included in the compose file are
- API (Actix Web)
- Database (Postgres)
- Monitoring - metrics (Jaeger)
You will also need to install some dependencies required to work with Diesel, i.e. the ORM used in this project. You can refer to the notes.md file.
To setup the database structure required by the API, you need to run the DB migration files. It is located in this directory.
The easiest way to run the migration here is by using the Diesel CLI
with the following command
diesel migration run
For more details, you can refer to the notes.md file.
You can just make a copy from .env.local
(the sample env file) and rename it as .env
.
To develop the Actix Web application itself, you need to first stop the core-api
service if you did spun it up using docker-compose in the previous steps.
After that, you can start the application via the following command
cargo run
It works just like any other Rust applications that use Cargo.
This project has been setup with utoipa to support OpenAPI doc generations.
After spinning up the API following the steps above, you can visit the Swagger UI at http://127.0.0.1:8080/swagger-ui/#
.
It will only be available when the env variable RUN_ENV=dev
.
I have written an article that explains about the Dockerfile
used in this project. It contains some information about running an Actix Web application that uses Diesel, as well as some steps to optimize Docker image size as well. You can check it out here on Codefee Time.
Items | Status |
---|---|
Actix Routes | ✅ |
Error Handling | ✅ |
Containerization | ✅ |
Observability - tracing with jaeger | ✅ |
OpenAPI - with utoipa | ✅ |
Auth | ⬜ |
? | ⬜ |