Interface: Handler

x2node-ws. Handler

Interface for web-service call handlers.

Extends

Methods


[METHOD](call)

Called to respond to the HTTP method same as the function's name. The returned value can be a ServiceResponse object, an Object, in which case it is serialized as JSON, a null to send back an HTTP 204 (No Content) response, or anything else, in which case it is converted to a string and sent back as plain text. The returned value can also be a Promise of any of the above. If the promise is rejected with a ServiceResponse, the response is sent back to the client. If rejected with anything else, an HTTP 500 (Internal Server Error) response is sent back.
Parameters:
Name Type Description
call module:x2node-ws~ServiceCall The call.
Returns:
The response.
Type
*

isAllowed(call)

Tell if the call is authorized to proceed. Returning false will cause either a 401 (Unauthorized) or a 403 (Forbidden) HTTP response depending on whether there is an authenticated actor or not.
Parameters:
Name Type Description
call module:x2node-ws~ServiceCall The call.
Inherited From:
Returns:
true if the call is allowed.
Type
boolean | Promise.<boolean>

OPTIONS(call, call)

If present on the handler, gives it a chance to add handler-specific headers to an OPTIONS HTTP request response.
Parameters:
Name Type Description
call module:x2node-ws~ServiceCall The call.
call module:x2node-ws~ServiceResponse The response.

<inner> getRepresentations(call)

If present on the handler, asks the handler what response content types are supported for the call. If not present on the handler, "application/json" is assumed.
Parameters:
Name Type Description
call module:x2node-ws~ServiceCall The call.
Returns:
Supported response content types.
Type
Array.<string>