Code Monkey home page Code Monkey logo

todo-actix's Introduction

Todo-actix

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

Why actix-web?

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

Why SeaORM?

  • 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

Starting DB, Jaeger UI (Visualize logs) and Consul (Service Discovery)

$ docker-compose up

Create 'todo-actix' database

$ 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'"

Running migrations

$ cd migrations
$ cargo run

Running in development mode

$ cargo run

Run in watch mode (cargo-watch is required):

cargo watch -x 'run --bin todo-actix'

Usage

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.

List Todos:

$ 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
}

Get Todo:

$ Coming soon...

Create Todo:

$ 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
  }
}

Update Todo:

$ coming soon...

Delete Todo:

$ coming soon...

Healthcheck:

$ 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"
}

Building

Dev

$ cargo build

Release

$ cargo build --release

Read more @ https://doc.rust-lang.org/book/ch14-00-more-about-cargo.html.

todo-actix's People

Contributors

yassineelbouchaibi avatar

Stargazers

 avatar  avatar

Watchers

 avatar

todo-actix's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.