The example app
This project and documentation are work in progress
To illustrate the concepts in this guide, I've written a simple Node application representing a community library app. You can view the code in this Github repository.
This app allows users to register, borrow books and return them. It speaks to a PostgreSQL database and issues events over a RabbitMQ pub/sub queue. Database operations are wrapped in transactions and the whole app is Dockerised to be easily run locally. In other words, it implements everything you'd expect from a real world app short of a CI script and production configuration.
I've done this because I felt the alternative was far too academic: it's one thing to lecture readers on how they should do something, another to demonstrate exactly how to do that when real world complications get in the way.
To run the app locally, you'll need Docker and the Docker Compose CLI. Just run docker-compose up
in the context of the repo and you'll boot up an app, a PostgreSQL and a RabbitMQ instance.
This app will be exposed on localhost:3000
and you can interact with it by using a HTTP dev client like Postman. Useful paths include
GET localhost:3000/health
- performs a healthcheck on the instance; if this doesn't return a 200 then something is going wrong with the containersPOST localhost:3000/user
- creates a user; do a search in the code forUserInput
to see the datastructure you'll need to postPOST localhost:3000/book
- same, but for creating a bookPOST localhost:3000/loan
- creates a loan; search forLoanInput
to see what data you needPOST localhost:3000/return/:bookId
- returns a book
Check the results of your action by connecting to the database on port 5432 with credentials "username" / "password", e.g. psql 0.0.0.0 -p 5432 user=username pw=password database=db
. You can also log in to the RabbitMQ management console at localhost:15672
with username / password as "guest".
Last updated