Skip to content

Parry-97/zero2prod-axum

Repository files navigation

zero2prod-axum

Newsletter service implemented in Rust using the Axum web framework, based on the "Zero To Production" book by Luca Palmieri.

Features:

  • Health check endpoint
  • Subscriber sign-up (POST /subscriptions)
  • Email confirmation flow (GET /subscriptions/confirm)
  • Newsletter publishing (POST /newsletters)
  • Integration with an external email API
  • Structured tracing and logging
  • Configuration via YAML and environment variables

Tech Stack:

  • Rust (edition 2024)
  • Axum, Tower, Tokio
  • SQLx (PostgreSQL)
  • Serde, Config, Secrecy
  • Tracing (tracing, tracing-subscriber)
  • Docker (for local PostgreSQL)

Directory Layout:

.
├── configuration/        # base, development, production YAML files
├── diagrams/             # architecture and flow diagrams
├── infra/                # IaC templates (e.g., Azure Bicep, Terraform)
├── migrations/           # SQL migrations (sqlx)
├── scripts/              # helper scripts (init_db.sh)
├── src/                  # application source code
│   ├── domain/           # core domain logic and types
│   ├── routes/           # HTTP handlers
│   ├── email_client.rs   # external email API client
│   ├── configuration.rs  # settings loader
│   ├── startup.rs        # app and router setup
│   └── main.rs           # entry point
└── tests/                # integration tests (api)

Getting Started

Prerequisites

  • Rust toolchain (1.68+)
  • Docker
  • sqlx-cli (install with cargo install sqlx-cli --no-default-features --features postgres)

Configuration

Copy and modify the sample YAML files in configuration/ or set environment variables prefixed with APP__ (e.g., APP__DATABASE__USERNAME).

Initialize the database

./scripts/init_db.sh

Run the service

cargo run

The API will be available at http://{host}:{port} as defined in your configuration.

Running Tests

Unit and integration tests can be executed with:

cargo test

Integration tests spin up an instance of the service and use wiremock to simulate the email API.

Usage

Use curl, Postman, or similar to interact with the endpoints:

  • GET /health_check
  • POST /subscriptions {"name": "...", "email": "..."}
  • GET /subscriptions/confirm?subscription_token=...
  • POST /newsletters {"title": "...", "content": {"text": "...", "html": "..."}}

Deploying

Infrastructure-as-code templates can be found in infra/. Adjust them for your cloud provider (e.g., Azure Bicep, Terraform).

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is provided for educational purposes only and does not include a license for production use.

About

Zero to Production implementation with Axum

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors