How to build a simple REST API using only Nginx and PostgreSQL.
Sometimes it’s overkill to use a web framework if you only need to develop a very simple REST API. It turns out that Nginx can be used to develop a full fledged REST API and PostgreSQL can easily be used for persistence.
In this blog post I’m going to show you how to create a simple CRUD API for articles.
I recommend that you use the OpenResty to install Nginx. It contains the standard Nginx core and lots of 3rd-party Nginx modules including the Postgres upstream module that allows Nginx to communicate with a PostgreSQL database. OpenResty is not an Nginx fork, just a software bundle so there’s nothing to worry about.
This is how I installed and compiled OpenResty on my Mac:
Remember to change pcre version number to the one you have installed. It might differ.
For this blog post I used PostgreSQL 9.2. You can install PostgreSQL from Homebrew or use Postgres.app .