Getting started with REST API Web Services in Rust using Axum, PostgreSQL, Redis, and JWT

(Draft)

GitHub: https://github.com/sheroz/axum-rest-api-sample


This sample starter project covers:


REST API based on axum

  • Routing
  • API versioning
  • CORS settings
  • Error handling (basic)
  • Graceful shutdown


Authentication & authorization using JSON Web Tokens (JWT)

  • Login, logout, refresh, and revoking operations
  • Role based authorization
  • Generating and validating access and refresh tokens
  • Setting tokens expiry time (based on configuration)
  • Using refresh tokens rotation technique
  • Revoking issued tokens by using Redis (based on configuration)
    • Revoke all tokens issued until the current time
    • Revoke tokens belonging to the user issued until the current time
    • Cleanup of revoked tokens


Using PostgreSQL database with SQLx driver

  • Database migrations
  • Async connection pooling
  • Async CRUD operations


Using Redis in-memory storage

  • Async Redis operations


Configuration settings

  • Loading and parsing .env file
  • Using environment variables


Logs


Tests

  • Docker based end-to-end tests
  • GitHub CI configuration for running tests


Using Docker for running services

  • PostgreSQL and Redis
  • Building the application using the official Rust image
  • Running the full stack: API + PostgreSQL + Redis


The source code is available on GitHub: https://github.com/sheroz/axum-rest-api-sample



IT / Coding / How-To


Other Topics