This is a simple todo server application to showcase the integration of the following technologies:
- rust: the language used for this project
- actix-web: the web framework used for this project
- utoipa: the openapi specification generator used for this project
- utoipa-swagger-ui: the swagger ui generator used for this project
- sea-orm: the ORM and database migration management tool used for this project
- postgres: the database used for this project
- serde: the serialization library used for this project
- dotenv: the environment variable management library used for this project
- config: the configuration management library used for this project
- tracing: the tracing library used for this project
- opentelemtry: the open telemetry library used for this project
- sentry: the error reporting library used for this project
- consul: the service discovery library used for this project
Next things I would like to do:
- Add production grade logging
- Add Sentry error reporting
- Add consul service registration
- Add an endpoint listing todos with apache arrow
- Add some tests
- Look into
anyhow
for error handling - Make a gRPC version of the API
- Revisit the project structure once it has been more than a few months and adjust it accordingly
- It's the most mature and stable web framework in the Rust ecosystem.
- It has the most contributors.
- Supports web socket and HTTP/2.
- Can be used with utoipa to generate OpenAPI specifications.
- Most performant rust web framework according to TechEmpower Web Framewok Benchmarks round 19 and second to best (by 0.4 %) on round 20.
- Sentry integration.
- Complete solution in interfacing with databases
- Acts as a both a database ORM and a migrations management tool at the same time.
- Not a lot of migrations management tool in Rust (Diesel is the only alternative).
- Pure rust driver for PostgreSQL.
Read more @ https://www.sea-ql.org/SeaORM/docs/internal-design/diesel
$ docker-compose up
$ docker-compose exec postgres bash -c "psql -U postgres -tc \"SELECT 1 FROM pg_database WHERE datname = 'todo-actix'\" | grep -q 1" || docker-compose exec postgres bash -c "createdb -U postgres 'todo-actix'"
$ cd migrations
$ cargo run
$ cargo run
Run in watch mode (cargo-watch is required):
cargo watch -x 'run --bin todo-actix'
The api can be explored and tested out in the browser through the swagger-ui interface available at http://127.0.0.1:8080/docs/. The logs can be viewed in the Jaeger UI interface available at http://localhost:16686/search?service=todo-actix. Consul is used to register the service with the consul agent. It can be viewed in the Consul UI.
$ curl -sv -X 'GET' http://127.0.0.1:8080/v1/todo/list?page=1&todos_per_page=10 | jq
>
> GET /v1/todo/list HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.68.0
> Accept: */*
>
< HTTP/1.1 200 OK
< content-length: 108
< content-type: application/json
< date: Sat, 25 Jun 2022 16:17:58 GMT
<
{
"todos": [
{
"id": 1,
"title": "First Todo ever!",
"completed": false
}
],
"page": 1,
"todos_per_page": 10,
"num_pages": 1
}
$ Coming soon...
$ curl -sv -X 'POST' \
'http://localhost:8080/v1/todo/create' \
-H 'Content-Type: application/json' \
-d '{
"title": "First Todo ever!"
}' | jq
> POST /v1/todo/create HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 34
>
< HTTP/1.1 201 Created
< content-length: 63
< content-type: application/json
< date: Sat, 25 Jun 2022 16:23:09 GMT
<
{
"todo": {
"id": 1,
"title": "First Todo ever!",
"completed": false
}
}
$ coming soon...
$ coming soon...
$ curl -sv -X 'GET' http://127.0.0.1:8080/healthcheck | jq
> GET /healthcheck HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-length: 22
< content-type: application/json
< date: Sun, 26 Jun 2022 19:45:37 GMT
{
"status": "Available"
}
$ cargo build
$ cargo build --release
Read more @ https://doc.rust-lang.org/book/ch14-00-more-about-cargo.html.