API()

Public APIs (accessible without any user credentials) should be defined as a subclass of @this. Override METHOD, PATH, QS, etc. to define the API. Swagger documentation will be automatically generated for your API. Don't instantiate API instances yourself. Define the subclass, and pass it to the service creation function from make-app.js and it will take care of setting up routing for your API, etc.

new API()

Members

abstract, static DESC

A human-readable description of what this API does. It is only used when automatically generating the Swagger documentation for the API. When used with the Swagger docs, newlines will be replaced with a single space character. May use Markdown formatting.

static NAME

The API's human-readable name. By default, this is computed by de-camel-casing the class name.

abstract, static PATH

The HTTP path suffix used to request this API.

protected, static swaggerSecurityConfig

BODY

The Schema describing the request body this API handles. Note that GET requests should not have request bodies. Use HTTP POST requests if request data size is too big to fit in the query string.

CORS_HEADERS

The header(s) which are allowed in CORS requests.

CORS_ORIGIN

The hostname from which this API can be called in a browser. By default this API cannot be called from a browser due to CORS policy (combined with the fact that no web application runs on our API subdomain).

ERRORS

Errors that may be returned from the API. Errors are subclasses of RequestError.

HEADERS

The Schema describing the HTTP headers this API handles, if any.

LOG_REQUEST_BODY_ON_ERROR

Whether to log request body to Sentry when error. For API with sensitive user data, this shouldn't set to true.

METHOD

The HTTP method used to request this API (e.g., GET, POST).

PATH_PARAMS

The Schema describing the path params this API handles, if any.

QS

The Schema describing the query string this API handles, if any.

RESPONSE

The schema describes the response body. This is used to verify that the implementation produces a correctly shaped output. It also speeds up JSON output serialization by 10-20%. This can return one of two things: 1) {@see ResponseSchema} - responses with HTTP 200 status codes will be validated against this schema. Non-200 responses can be anything. This is the typical return value. 2) A subclass of {@see RequestDone}. The default is to not allow any output on HTTP 200 responses.

TAG

Tag used to group APIs in the generated Swagger documentation. Set to null to exclude it from the generated Swagger documentation.

Methods

static getInputsToTrackWithSentry()

Returns a map of inputs to track in Sentry's context. By default, includes the query string, path params and body. This provides helpful debugging information but should only be used if these fields don't include sensitive information.

__trackInputsWithSentry()

Adds inputs from the query string, path params and body to the Sentry context. This provides helpful debugging information but should only be used if these fields don't include sensitive information.

async, abstract, protected computeResponse(req) → {Object|String}

The API logic. This method is called after all inputs are validated according to the schemas specified by the API definition.
Parameters:
Name Type Description
req Request the fastify request object being handled
Returns:
Object | String - optional JSON-able object or string to send back as the HTTP response body

protected getHeadersToForward()

Gets headers from this request that should be forwarded. By default, this is all headers defined in HEADERS.

protected redirectToWebApp(schemeAndHostopt, pathopt, qsParamsopt, cookieopt)

Redirects to a URL optionally with query string and cookie. Any headers to forward (that were sent to the request which is calling this function) will be added to the existing cookie's JSON data, if any.
Parameters:
Name Type Attributes Description
schemeAndHost String <optional>
e.g., https://my-webapp.example.com
path String <optional>
the version of the web application to launch; can be overridden by query parameter "version" but otherwise defaults to the version of the service which served the web app
qsParams Object <optional>
the query string parameters to launch with
cookie Object <optional>
cookie data to send (good for sensitive values which should not be passed in the query string)

setSentryContext()

Sets context to be transmitted to Sentry if this request fails.

setSentryTag()

Sets a tag to be transmitted to Sentry if this request fails.

setSentryUserInfo()

Sets user info to be transmitted to Sentry if this request fails.