DriLLFreAK100 / codefee-works-api

Just an experimental API project written in Rust
9 stars 2 forks source link

1. Intro

This is just an experimental project to explore building a web service or API in Rust. It uses the powerful Actix Web framework.

2. How to run?

Easiest way to spin up a working sample of this repo is via Docker Compose

2.1 Docker Compose

To spin up the entire stack on local, just run the following command (depending on your target architecture).

  1. 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
  1. 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

2.2 Diesel

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.

2.3 Running the DB Migrations

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.

2.4 .env file

You can just make a copy from .env.local (the sample env file) and rename it as .env.

2.5 For Local Development

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.

3. OpenAPI (Swagger)

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.

4. About the Dockerfile

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.

5. Things to do

Items Status
Actix Routes :white_check_mark:
Error Handling :white_check_mark:
Containerization :white_check_mark:
Observability - tracing with jaeger :white_check_mark:
OpenAPI - with utoipa :white_check_mark:
Auth :white_large_square:
? :white_large_square: