wix-http-functions.WixHttpFunctionResponse

wix-http-functions.WixHttpFunctionResponse

An object representing a response to an HTTP function request.

Contents

body Sets or gets the body of the response as a string or binary buffer.
headers Sets or gets the HTTP response header fields.
status Sets or gets the HTTP status code of the response.
body

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

Number | Buffer

Examples

Get the response body

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBib2R5ID0gcmVzcG9uc2UuYm9keTsgLy8gImJvZHkgdGV4dCIKCn0K
// In http-functions.js

export function use_myFunction(request) {

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

}

Set the response body

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIHJlc3BvbnNlLmJvZHkgPSAiYm9keSB0ZXh0IjsKCn0K
// In http-functions.js

export function use_myFunction(request) {

  response.body = "body text";

}
headers

headers

Sets or gets the HTTP response header fields.

Syntax

get headers(): Object
set headers(value: Object): void

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.

Type

Object

Examples

Get the response headers

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBoZWFkZXJzID0gcmVzcG9uc2UuaGVhZGVyczsKCiAgLyogaGVhZGVyczoKICAgKiB7CiAgICogICAiY29udGVudC10eXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAqICAgImxhc3QtbW9kaWZpZWQiOiAiVHVlLCAyNiBTZXAgMjAxNyAwMDowMDowMCBHTVQiCiAgICogfQogICAqLwoKfQo=
// 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

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGNvbnN0IGhlYWRlcnMgPSB7CiAgICAiY29udGVudC10eXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgImxhc3QtbW9kaWZpZWQiOiAiVHVlLCAyNiBTZXAgMjAxNyAwMDowMDowMCBHTVQiCiAgfTsKCiAgcmVzcG9uc2UuaGVhZGVycyA9IGhlYWRlcnM7Cgp9Cg==
// 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

status

Sets or gets the HTTP status code of the response.

Syntax

get status(): Number
set status(value: Number): void

Type

Number

Examples

Get the response's HTTP status code

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBzdGF0dXMgPSByZXNwb25zZS5zdGF0dXM7IC8vIDIwMAoKCn0K
// In http-functions.js

export function use_myFunction(request) {

  let status = response.status; // 200


}

Set the response's HTTP status code

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIHJlc3BvbnNlLnN0YXR1cyA9IDIwMDsKCn0K
// In http-functions.js

export function use_myFunction(request) {

  response.status = 200;

}