An example JSON API server using Postgres and Express
Created to help me learn the JSON API format. It uses the MassiveJS library to access a Postgres database.
npm install
You'll need Postgres to be installed and running. You can then setup the database:
npm run setup-database
Start the server:
npm start
This will start a server running at http://127.0.0.1:3000.
The API implements the basic CRUD actions for a single collection:
GET /people
POST /people
GET /people/:id
PATCH /people/:id
DELETE /people/:id
The GET /people
route supports sorting as described in the sorting specification. Multiple sort fields can be used together:
GET /people?sort=surname,-name HTTP/1.1
Page-based pagination is implemented as per the pagination specification:
GET /people?page[number]=2&page[size]=1 HTTP/1.1
The filter
parameter can be used to filter records as described in the recommendations for filtering:
GET /people?filter[name]=Ron&filter[surname]=Weasley HTTP/1.1