A newsletter subscription service built with Rust and actix-web
- Rust toolchain (1.70+)
- Docker (for running Postgres)
sqlx-cli:cargo install sqlx-cli --no-default-features --features rustls,postgres
-
Start the database:
./scripts/init_db.sh
-
Run the application:
cargo run
The server will start at http://127.0.0.1:8000.
GET /health_checkReturns 200 OK if the service is running.
POST /subscribe
Content-Type: application/x-www-form-urlencoded
name=John+Doe&[email protected]Subscribes a user to the newsletter. Returns 200 on success, 400 on invalid request and 500 on database error.
Run tests:
cargo testFormat code:
cargo fmtLint:
cargo clippyCheck dependencies:
cargo deny check advisoriesWatch mode (auto-reload on changes):
cargo watch -x 'clippy --all-features --all-targets -- -D warnings' -x test -x run | bunyanTip
bunyan is used to prettify the telemetry logs, you can install it via npm or cargo install bunyan.
Settings are in config.yaml:
application_port: HTTP server port (default: 8000)database: PostgreSQL connection details:username,password,host,port,database_name
The application uses PostgreSQL with the following schema:
- subscriptions table:
id(UUID, primary key)email(TEXT, unique)name(TEXT)subscribed_at(TIMESTAMPTZ)
Migrations are in migrations/ and run automatically via sqlx.
DATABASE_URL: PostgreSQL connection string (set byinit_db.sh)TEST_LOG: Enable logging output for testsSKIP_DOCKER: Skip Docker container creation ininit_db.sh