CorvidReference

WixHttpFunctionResponse

An object representing a response to an HTTP function request.

Table of Contents

PROPERTIES

?
Store values associated with an object.
bodySets or gets the body of the response as a string or binary buffer.
headersSets or gets the HTTP response header fields.
statusSets or gets the HTTP status code of the response.

body

Sets or gets the body of the response as a string or binary buffer.

Syntax

get body(): string | Buffer
set body(value: string | Buffer): void
TYPE
?
The kind of data the property stores.
string | Buffer

Examples

Get the response body

// In http-functions.js

export function use_myFunction(request) {

  let body = response.body; // "body text"

}

Set the response body

// In http-functions.js

export function use_myFunction(request) {

  response.body = "body text";

}

headers

Sets or gets the HTTP response header fields.

Description

The headers property contains an object of key:value pairs where the key is the header field name and the value is the header field value.

Syntax

get headers(): Object
set headers(value: Object): void
TYPE
?
The kind of data the property stores.
Object

Examples

Get the response headers

// In http-functions.js

export function use_myFunction(request) {

  let headers = response.headers;

  /* headers:
   * {
   *   "content-type": "application/json",
   *   "last-modified": "Tue, 26 Sep 2017 00:00:00 GMT"
   * }
   */

}

Set the response headers

// In http-functions.js

export function use_myFunction(request) {

  const headers = {
    "content-type": "application/json",
    "last-modified": "Tue, 26 Sep 2017 00:00:00 GMT"
  };

  response.headers = headers;

}

status

Sets or gets the HTTP status code of the response.

Syntax

get status(): number
set status(value: number): void
TYPE
?
The kind of data the property stores.
number

Examples

Get the response's HTTP status code

// In http-functions.js

export function use_myFunction(request) {

  let status = response.status; // 200


}

Set the response's HTTP status code

// In http-functions.js

export function use_myFunction(request) {

  response.status = 200;

}