The mocking module of the webserver adapter.
This module implements the handler functions that serve mock data from the examples defined under the responses section of the endpoint descriptors
Used only internally by the adapter.
Methods
(static) callMockingServiceFunction(container, endpoint, req, res, next)
Call the generic mocking service function that provides responses to the incoming requests using the examples defined for the endpoint.
The function tries to respond the content and representation format that is accepted by the client.
If there is no example found with the right media-type, then a 415 Unsupported Media Type
error will be responded.
NOTE: Currently a single mime-type value is accepted without weight.
TODO: Implement multiple values ordered by weight when find the right example response.
Parameters:
Name | Type | Description |
---|---|---|
container |
Object | The container context |
endpoint |
Object | The endpoint descriptor |
req |
Object | The request object |
res |
Object | The response object |
next |
function | An error-first call-back that the service function must call at the end, to pass the control to the next middleware function. |
(static) determineMediaType(container, endpoint, accept) → {String|null}
Determine the resultant media-type for the response
Parameters:
Name | Type | Description |
---|---|---|
container |
Object | The container context |
endpoint |
Object | The endpoint decriptor object |
accept |
String | The actual value of the "Accept" header of the request, or |
Returns:
The resultant media-type that will be the value of the Content-Type
header. If the Accept
header is specific, but it is not supported by the endpoint, then returns with null
.
- Type
- String | null
(static) getMockingResponse(container, endpoint, req)
Get the mocking response from the endpoint descriptor and from the request parameters.
If there is no example found with the right media-type, then a 415 Unsupported Media Type
error will be returned.
NOTE: Currently a single mime-type value is accepted without weight.
TODO: Implement multiple values ordered by weight when find the right example response.
Parameters:
Name | Type | Description |
---|---|---|
container |
Object | The container context |
endpoint |
Object | The endpoint descriptor |
req |
Object | The request object |