Using the WixHttpFunctionResponse
object, you define an appropriate response after the handling of an
incoming request. There are a number of functions
you can use to create the WixHttpFunctionResponse
, such as:
To define the response, set the body
, headers
, and status
properties.
Notes:
This API is only intended for use in server-to-server communications. If you use this API to set a cookie on a site visitor's browser you may no longer be in compliance with applicable data privacy regulations.
All of the above functions except response()
always create a response object with a pre-set HTTP status code (e.g. for ok()
this is always 200), which cannot be overridden.
Sets or gets the body of the response as a string, object or binary buffer.
Sets or gets the HTTP response header fields.
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.
When defining a content-type
key, note that for Free sites,text/html
is not
supported. Premium sites support all content types.
// 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"
* }
*/
}