To understand how requests are processed in Dominion framework lets look on their lifecycle, it’s straight forward:
On startup framework goes through all registered controllers, generates URI based on functions interface and make mappings between URI’s and those functions.
Client makes request to API server.
Framework’s router catches a request and looking for matching endpoints from ones registered in controllers.
If match was found, router builds request Promise chain. This means that
all functions in a chain will receive as an argument execution result of previous
function or Promise resolution returned by previous function. Also, if any of
the function throws an exception all consequent functions will not be executed,
unless there will be
.catch() with manual exception handling.
A chain contains request interceptors, endpoint function (function defined in a controller), response interceptors and request finalisation. Afterwards, request promise chain gets executed.
requestInterceptorsarray in component’s declaration file. They are general purpose functions that may validate client’s authorization.
endpointgets executed. It defines top level business logic. Usually controller’s
endpointsmanipulates models created by
Factories. If needed, factories or model instances call linked
Repositoryto create/modify/remove data in DB or other permanent storage.
endpointmay return Promise, serializable Object or primitive.
endpointexecution is passed to response interceptors. They are taking from
responseInterceptorsarray in component’s declaration file. There are no common use for response interceptor, as
endpointis responsible to produce response that is ready to be send back to client. However, it may be used to perform some general actions that depends on
endpoint's response, like set custom header.
Repositoy. If any, it will set proper status code (400 - for bad request, 404 - if model not found, 409 - for conflicts, etc).
After it’s done, response produced by all previous steps gets stringified and returned to a client.