Endpoint is defined in routes/routeName.js. This file contains metadata about the endpoint and functions to get and process data.
Endpoint definition file is require()ed from index.js when the app starts.
The .endpoint() function in the endpoint definition file defines the endpoint on the app object.
It would be better to reduce the responsibility of the route definition files by moving instantiation of the routes to index.js and using an Endpoint class. This has many benefits:
less code duplication between the endpoint definition files (removes instantiation function and dependency on the endpoint helper function)
endpoint definition files are ignorant of the app, containing only endpoint-related logic and configuration
the route creation process goes from app -> route -> endpoint helper to app -> Endpoint -> route config, a top-down approach, which makes more sense in this situation
The endpoint loading process has several parts:
routes/routeName.js
. This file contains metadata about the endpoint and functions to get and process data.require()
ed fromindex.js
when the app starts..endpoint()
function in the endpoint definition file defines the endpoint on theapp
object.It would be better to reduce the responsibility of the route definition files by moving instantiation of the routes to
index.js
and using anEndpoint
class. This has many benefits:app -> route -> endpoint helper
toapp -> Endpoint -> route config
, a top-down approach, which makes more sense in this situationSee #11, section on endpoint classes.