REST API structure
Versioning
The API is versioned to enable future backwards compatibility in case of a major upgrade of the project.
This is achieved by separating the routes from the beginning to v1
provisioning.
Example: https://myfundomainname.com/api/v1/*
where in case of an upgrade the v2
would just use https://myfundomainname.com/api/v2/*
route.
Body and Query for Route validation
Each request that contains external data, be it through search queries or POST body, has to have the values validated and properly typed in the route definition.
This is done through validation schemas of express-validator
library
Route definition declarations guide
In order to better and/or more strictly type the codebase, every new route will have to follow these rules:
Every route in /routes folder should have corresponding file inside /definitions named the same only with .d (definitions) before the .ts file type ending
Inside the routes definitions file, there should be a namespace named the same as the class inside the routes folder which is being typed. The same namespace is the default export of that file. There should also be an enum in which every route/method is defined
Every namespace should implement next generics:
ResponseBody<T extends ENameOfTheRoute>
- Returns specified routes response bodyRequestBody<T extends ENameOfTheRoute>
- Returns specified routes request bodyRequestQueries<T extends ENameOfTheRoute>
- Returns specified routes query paramsRequestParams<T extends ENameOfTheRoute>
- Returns specified routes request paramsResponse<T extends ENameOfTheRoute>
- Returns expressjs response objectRequest<T extends ENameOfTheRoute>
- Returns expressjs request objectRouteMethod<T extends ENameOfTheRoute>
- Returns typization for next function
Every generic should return default empty object if route wasn't implemented
The naming convention is PascalCase/UpperCamelCase and it should look something like this:
For namespace name
{ROUTE_NAME}Definitions
- AuthRouteDefinitions
For enum name
E{ROUTE_NAME}
- EAuthRoute
For enum values
{HTTP_METHOD}{ROUTE_NAME}
- GetMe
Last updated