Request and response objects

This page lists every field and method on the request, response, and event objects a PubNub Function handler receives, by trigger type. For handler structure, Promises, and chaining, see Functions development. For what each trigger does, see Function types.

Standard request object​

PubNub passes this object to the handler for every trigger type except On Request, On Interval, and Subscribe on Interval.

Methods​

MethodArgumentsDescription
ok(message?)message: String (optional)Resolves the execution and returns a Promise that resolves to the value of the request object. The event continues normally.
abort(message?)message: String (optional)Resolves the execution and returns a Promise that resolves to the value of the request object, with an error code added. On synchronous triggers, PubNub does not deliver the message.
1export default (request) => {
2 if (!request.message.valid) {
3 return request.abort('invalid payload');
4 }
5 return request.ok();
6};

Attributes​

AttributeTypeDescription
messageObjectThe message payload.
channelsArray<String>Channels the message was published to.
verbStringPublish method the client used.
pubkeyStringPublish key used to send the message.
subkeyStringSubscribe key for the channel.
meta.clientipStringIP address of the publishing client.
meta.originStringOrigin configured on the publishing client.
meta.useragentStringUser agent string of the publishing client.
paramsObjectURL parameters on the request.
uriStringRequest URI.
versionStringAPI version.

On Request: request and response​

request attributes​

AttributeTypeDescription
methodStringHTTP method: GET, PUT, POST, DELETE.
bodyObjectRequest body.
headersObjectRequest headers.
paramsObjectURL query parameters.
pathStringPath configured for the Function, minus the PubNub hostname and key information.
uriStringFull request URI.
verbStringAlways rest.
pubkeyStringPublish key.
subkeyStringSubscribe key.
meta.clientipStringIP address of the caller.
meta.originStringOrigin of the caller.
meta.useragentStringUser agent of the caller.
versionStringAPI version.

response methods​

MethodArgumentsDescription
send(body?)body: String (optional)Sends the response, ends the Function execution, and returns a Promise that resolves to the value of the response object.

response attributes​

AttributeTypeDescription
statusNumberHTTP status code returned to the caller. Set before calling send().
bodyObjectResponse body returned to the caller.
headersObjectResponse headers returned to the caller.

On Request Functions receive HTTP requests. The request object represents the incoming HTTP request.

On Interval: event object​

PubNub passes this object to the handler for the On Interval trigger.

Methods​

MethodArgumentsDescription
ok()NoneResolves the execution and returns a Promise that resolves to the value of the event object.

Attributes​

AttributeTypeDescription
execIntervalNumberConfigured interval, in milliseconds.
lastTimestampNumberTimestamp of the previous execution.
timestampNumberTimestamp of the current execution.
verbStringAlways interval.
pubkeyStringPublish key.
subkeyStringSubscribe key.

Subscribe on Interval: event object​

Subscribe on Interval uses the same event object as On Interval (above).

Was this page useful?

Last updated on