{"id":24276245,"url":"https://github.com/sheroz/axum-rest-api-sample","last_synced_at":"2026-06-07T01:02:09.659Z","repository":{"id":206557063,"uuid":"716650653","full_name":"sheroz/axum-rest-api-sample","owner":"sheroz","description":"Building REST API Web service in Rust using axum, JSON Web Tokens (JWT), SQLx, PostgreSQL, and Redis.","archived":false,"fork":false,"pushed_at":"2025-09-17T19:23:43.000Z","size":305,"stargazers_count":76,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-09-17T21:34:12.520Z","etag":null,"topics":["api","api-rest","cors","docker","jwt","logging","postgres","redis","rest-api","web-server","web-service"],"latest_commit_sha":null,"homepage":"https://sheroz.com/pages/blog/rust-axum-rest-api-postgres-redis-jwt-docker.html","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sheroz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-11-09T15:25:52.000Z","updated_at":"2025-09-17T19:19:15.000Z","dependencies_parsed_at":"2024-01-14T18:48:52.631Z","dependency_job_id":"b0c1ba8d-8eb3-4f70-ab98-837958832322","html_url":"https://github.com/sheroz/axum-rest-api-sample","commit_stats":null,"previous_names":["sheroz/axum-web","sheroz/axum-rest-api-sample"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/sheroz/axum-rest-api-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Faxum-rest-api-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Faxum-rest-api-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Faxum-rest-api-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Faxum-rest-api-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sheroz","download_url":"https://codeload.github.com/sheroz/axum-rest-api-sample/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheroz%2Faxum-rest-api-sample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276801522,"owners_count":25707312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-24T02:00:09.776Z","response_time":97,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-rest","cors","docker","jwt","logging","postgres","redis","rest-api","web-server","web-service"],"created_at":"2025-01-15T22:26:25.002Z","updated_at":"2025-09-24T18:31:27.485Z","avatar_url":"https://github.com/sheroz.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Getting started with REST API Web Services in Rust using Axum, JWT, SQLx, PostgreSQL, and Redis\n\n[![build \u0026 test](https://github.com/sheroz/axum-web/actions/workflows/ci.yml/badge.svg)](https://github.com/sheroz/axum-web/actions/workflows/ci.yml)\n[![MIT](https://img.shields.io/github/license/sheroz/axum-web)](https://github.com/sheroz/axum-web/tree/main/LICENSE)\n\nThis project demonstrates how to build a REST API web server in Rust using `axum`, `JSON Web Tokens (JWT)`, `SQLx`, `PostgreSQL`, and `Redis`\n\nThe REST API web server supports JWT-based authentication and authorization, asynchronous database operations for user and account models, a basic transaction example that transfers money between accounts, and detailed API error handling in a structured format.\n\nThe brief description: [rust-axum-rest-api-postgres-redis-jwt-docker.html](https://sheroz.com/pages/blog/rust-axum-rest-api-postgres-redis-jwt-docker.html)\n\n## Covers\n\n- REST API web server based on [axum](https://github.com/tokio-rs/axum)\n  - Routing and request handling\n  - API versioning\n  - API Error handling using structured format\n  - Cross-Origin Resource Sharing (CORS)\n  - Graceful shutdown\n- Authentication \u0026 authorization using `JSON Web Tokens (JWT)`\n  - Login, logout, refresh, and revoking operations\n  - Role based authorization\n  - Generating and validating access and refresh tokens\n  - Setting tokens expiry time (based on configuration)\n  - Using refresh tokens rotation technique\n  - Revoking issued tokens by using Redis (based on configuration)\n    - Revoke all tokens issued until the current time\n    - Revoke tokens belonging to the user issued until the current time\n    - Cleanup of revoked tokens\n- Using `PostgreSQL`database with `SQLx`\n  - Database migrations\n  - Async connection pooling\n  - Async CRUD operations and transactions\n- Using `Redis` in-memory storage\n  - Async `Redis` operations\n- Configuration settings\n  - Loading and parsing `.env` file\n  - Using environment variables\n- Logs\n  - `tracing` based logs\n- Tests\n  - End-to-end API tests\n  - Database isolation in tests\n- Using `Docker`\n  - Running `PostgreSQL` and `Redis` services\n  - Building the application using the official `Rust` image\n  - Running the full stack: API + `PostgreSQL` + `Redis`\n- GitHub CI configuration\n  - Running `cargo deny` to check for security vulnerabilities and licenses\n  - Running `cargo fmt` to check for the Rust code format according to style guidelines\n  - Running `cargo clippy` to catch common mistakes and improving the Rust code\n  - Running tests\n  - Building the application\n\n## REST API Endpoints\n\n- List of available API endpoints: [docs/api-docs.md](/docs/api-docs.md)\n- API request samples in the format RFC 2616: [tests/endpoints.http](/tests/endpoints.http)\n\n## API Request Samples\n\n- Using [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) for Visual Studio Code,\nsupports RFC 2616, request samples: [tests/endpoints.http](/tests/endpoints.http).\n- Using [curl](https://curl.se/):\n\n  Health check\n\n  ```shell\n  curl -i http://127.0.0.1:8080/v1/health\n  ```\n\n  Login\n\n  ```shell\n  curl -i http://127.0.0.1:8080/v1/auth/login \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"username\":\"admin\",\"password_hash\":\"7c44575b741f02d49c3e988ba7aa95a8fb6d90c0ef63a97236fa54bfcfbd9d51\"}'\n  ```\n\n  List of users\n\n  ```shell\n  curl -i http://127.0.0.1:8080/v1/users \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJkNTFlNjE4Ny1jYmFjLTQ0ZmEtOWE5NS04ZjFkZWJkYmFlZWEiLCJqdGkiOiIwN2Y3OWE0OC1kMWFhLTQ1ZjItOWE5NS05Y2M5MGZiY2UyYTciLCJpYXQiOjE3MzYwMTA3MjIsImV4cCI6MTczNjAxNDMyMiwidHlwIjowLCJyb2xlcyI6ImFkbWluIn0.3f2c_5PyPXMhgu0FIX4--SGjnSDW1GLxL0ba6gSImfM\"\n  ```\n\n## Running end-to-end API tests\n\nREST API tests: [/tests](/tests)\n\n```shell\ndocker-compose up -d\ncargo test\n```\n\n## Running the service (debug build)\n\n```shell\ndocker-compose up -d\ncargo run\n```\n\n## Running the service in test configuration\n\n```shell\nENV_TEST=1 cargo run\n```\n\n## Running the service at a specific log level\n\nSetting the `RUST_LOG` - logging level on the launch:\n\n```shell\nRUST_LOG=info,hyper=debug,axum_web=trace cargo run\n```\n\n## Running the Docker based full stack build\n\n```shell\ndocker-compose -f docker-compose.full.yml up -d\n```\n\n## Project Stage\n\n**Development**: this project is under development.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheroz%2Faxum-rest-api-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsheroz%2Faxum-rest-api-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheroz%2Faxum-rest-api-sample/lists"}