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
| Method | Arguments | Description |
|---|---|---|
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
| Attribute | Type | Description |
|---|---|---|
message | Object | The message payload. |
channels | Array<String> | Channels the message was published to. |
verb | String | Publish method the client used. |
pubkey | String | Publish key used to send the message. |
subkey | String | Subscribe key for the channel. |
meta.clientip | String | IP address of the publishing client. |
meta.origin | String | Origin configured on the publishing client. |
meta.useragent | String | User agent string of the publishing client. |
params | Object | URL parameters on the request. |
uri | String | Request URI. |
version | String | API version. |
On Request: request and response
request attributes
| Attribute | Type | Description |
|---|---|---|
method | String | HTTP method: GET, PUT, POST, DELETE. |
body | Object | Request body. |
headers | Object | Request headers. |
params | Object | URL query parameters. |
path | String | Path configured for the Function, minus the PubNub hostname and key information. |
uri | String | Full request URI. |
verb | String | Always rest. |
pubkey | String | Publish key. |
subkey | String | Subscribe key. |
meta.clientip | String | IP address of the caller. |
meta.origin | String | Origin of the caller. |
meta.useragent | String | User agent of the caller. |
version | String | API version. |
response methods
| Method | Arguments | Description |
|---|---|---|
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
| Attribute | Type | Description |
|---|---|---|
status | Number | HTTP status code returned to the caller. Set before calling send(). |
body | Object | Response body returned to the caller. |
headers | Object | Response 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
| Method | Arguments | Description |
|---|---|---|
ok() | None | Resolves the execution and returns a Promise that resolves to the value of the event object. |
Attributes
| Attribute | Type | Description |
|---|---|---|
execInterval | Number | Configured interval, in milliseconds. |
lastTimestamp | Number | Timestamp of the previous execution. |
timestamp | Number | Timestamp of the current execution. |
verb | String | Always interval. |
pubkey | String | Publish key. |
subkey | String | Subscribe key. |
Subscribe on Interval: event object
Subscribe on Interval uses the same event object as On Interval (above).
Related reference
- Functions development. Handler structure, Promises, and chaining and forking.
- Function types. What each trigger type does and when to use it.
- Modules and libraries. Built-in module APIs, including the
pubnubmodule.