Update

See profile API for an up-to-date example

File Structure

Figure 1: File Structure as of 02/10/2020

Figure 1: File Structure as of 02/10/2020

The file structure we are using is demonstrated in Figure 1 above. Our API is organised into components, for example "profile" and "upload". These components are a logical grouping of endpoints. For instance, "profile" is responsible for the endpoints concerning creating, retrieving, updating and deleting profile information. It also happens to be that the "profile" endpoints are:

Inside each component folder, you should find 4 files:

import { profileValidation } from './validator';
import { addUser } from './routes';

	...

router.post('/', profileValidation, addUser);

Middleware which are not specific to a component can be put inside the middleware folder. For example the auth file contains middleware for authenticating a user (which is useful across many different components).

The src/index file simply starts the server, and calls the src/routes file, which registers the routes and middleware to the application.

You should be able to jump into creating an API endpoint by copying the basic structure of one already written.

Express Server

We are running an Express server. You can learn more here:

Express - Node.js web application framework

Validation

I recommend the "express-validator" package for validation. You can find the package here:

Getting Started · express-validator

Postgres

We use postgreSQL for our database. The package we are using is:

Welcome

Getting user email

Sample Use Cases: Scopes and Claims