A "Routes handler" is the element at charge of handling the routes variants declarations, and sending the appropriate response.
Mocks Server includes only one Routes Handler by default, which accepts routes variants declared in the format described in the
routes chapter, but you can add your own route variants formats.
This feature, combined with the plugins development, gives you the possibility of adding to Mocks Server almost every new feature you want.
A Routes Handler should be defined as a
static get id()#
This static getter will be used to recognize the Routes Handler. When defining a route variant, the handler to be used can be defined using the
handler property. That property in route variants should be the
id of the Route Handler to be used.
route: All route and route variants properties from the
variantId, and all other properties defined in the route variant object).
middleware(req, res, next)#
This is the middleware that will be called when the route url matches and the specific variant should be used.
This getter should return a plain object containing an approached preview of the response that will be sent when the route variant is used. This is useful to provide information to other plugins or Mocks Server interfaces.
Here you have an example of how a custom Routes Handler should be defined:
Then you can add your custom Routes Handler using the
And now, you can use the custom handler when defining route variants: