RESTful Code Structure
Notes on structuring the code for a RESTful code base

Good practices is to organise code to separate concerns.
For an API there are three layers
- Web layer
- Service layer
- Data access layer
Web layer
The web layer is where we process HTTP requests, interface with the service layer and return a http response.
The main abstractions utilised in the web layer include:
- Routes: where we declare API endpoints and associated controllers
- Controllers: is where we unpack the endpoint request and interface with services
- Middleware: is where we include reusable code that modify requests for things such as cache control, authentication, error handling etc.
Routes
Route endpoints should be separated into entities which are then broken down into actions.
- Get
- Get one
- Post
- Delete
Controllers
Controllers should be unpacking the HTTP request such as headers, URL parameters, body data etc. before sending actions to the services layer
Middleware
Middleware hold functions that are common across routes.
Service Layer
The service layer is where we apply the business logic and make requests of the data layer.
Data Layer
This is where we communicate with the database.