td-bn / ss-z2p

Following along zero2prod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple Newsletter API

An API for creating a backend application in Rust using the actix framework that handles the various functionalities of a newsletter.

Following along the Rust: Zero to Production book with some changes here and there.

Testing

Start a local instance of (migrated) DB using:

./scripts/init_db.sh

Then, simply run tests using cargo test

How to run

Save the following env variables in a .env file:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=newsletter
  • Build the image using the dockerfile
docker build --tag z2p --file Dockerfile .
  • Compose with postgres using
docker-compose up 
  • Run migrations using
DATABASE_URL=postgres://postgres:password@localhost:5432/newsletter sqlx migrate run

Make sure you use the correct database url based on your env variables.

Interacting with app

Run:

curl --request POST --data 'name=le%20guin&email=ursula_le_guin%40hotmail.com' 127.0.0.1:8000/subscriptions -v

You should get a 200 response code.

About

Following along zero2prod


Languages

Language:Rust 94.9%Language:Shell 2.9%Language:Dockerfile 1.8%Language:PLpgSQL 0.4%