wix-http-functions.WixHttpFunctionRequest

wix-http-functions.WixHttpFunctionRequest

An object representing an incoming request received by a call to an HTTP function.

The WixHttpFunctionRequest object breaks the URL of the incoming call to an HTTP function into different parameters for easy access.

Premium Sites

Given the premium site function call:

https://www.domain.com/_functions/myFunction/sub?q=value

The URL is broken down as shown in the table below:

url
baseUrl path query
https://www.domain.com/_functions /myFunction/sub ? q=value

Free Site

Given the free site function call:

https://user.wixsite.com/mysite/_functions/myFunction/sub?q=value

The URL is broken down as shown in the table below:

url
baseUrl path query
https: //user.wixsite.com/mysite/_functions /myFunction/sub ? q=value

Contents

baseUrl Returns the base URL of a call to an HTTP function.
body Returns an object representing the body of the incoming call to an HTTP function.
functionName Returns the function name of a call to an HTTP function.
headers Returns the HTTP header fields used in a call to an HTTP function.
ip Returns the IP address of the client who called the HTTP function.
method Returns the HTTP method used in calling an HTTP function.
path Returns the path of the URL used to call an HTTP function.
query Returns the query fields and values of the URL used to call an HTTP function.
url Returns the full URL of a call to an HTTP function.
WixHttpFunctionRequestBody An object returned by the body property representing the body of a call to an HTTP function.
baseUrl

baseUrl

Returns the base URL of a call to an HTTP function.

Syntax

get baseUrl(): String

Description

Premium sites: Premium site baseUrl

Free sites: Free site baseUrl

Type

String

Examples

Get the base URL of a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBiYXNlVXJsID0gcmVxdWVzdC5iYXNlVXJsOwogIC8vIFByZW1pdW0gc2l0ZTogImh0dHBzOi8vd3d3LmRvbWFpbi5jb20vX2Z1bmN0aW9ucyIKICAvLyBGcmVlIHNpdGU6ICJodHRwczovL3VzZXIud2l4LXNpdGVzLmNvbS9teXNpdGUvX2Z1bmN0aW9ucyIKCn0K
// In http-functions.js

export function use_myFunction(request) {

  let baseUrl = request.baseUrl;
  // Premium site: "https://www.domain.com/_functions"
  // Free site: "https://user.wix-sites.com/mysite/_functions"

}
body

body

Returns an object representing the body of the incoming call to an HTTP function.

Syntax

get body(): WixHttpFunctionRequestBody

Description

Use the functions of the returned WixHttpFunctionRequestBody object to get the body in a number of formats.

Type

WixHttpFunctionRequestBody

Examples

Get the body from a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIHJlcXVlc3QuYm9keS50ZXh0KCkKICAgIC50aGVuKCAoYm9keSkgPT4gewogICAgICBsZXQgcmVxdWVzdEJvZHkgPSBib2R5OwogICAgfSApOwoKfQo=
// In http-functions.js

export function use_myFunction(request) {

  request.body.text()
    .then( (body) => {
      let requestBody = body;
    } );

}
functionName

functionName

Returns the function name of a call to an HTTP function.

Syntax

get functionName(): String

Description

Premium sites: Premium site URL

Free sites: Free site URL

Type

String

Examples

Get the function name of a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBmdW5jdGlvbk5hbWUgPSByZXF1ZXN0LmZ1bmN0aW9uTmFtZTsgLy8gbXlGdW5jdGlvbgoKfQo=
// In http-functions.js

export function use_myFunction(request) {

  let functionName = request.functionName; // myFunction

}
headers

headers

Returns the HTTP header fields used in a call to an HTTP function.

Syntax

get headers(): Object

Description

The headers property returns 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 headers from a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBoZWFkZXJzID0gcmVxdWVzdC5oZWFkZXJzOwogIC8vIHsiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24ifQoKfQo=
// In http-functions.js

export function use_myFunction(request) {

  let headers = request.headers;
  // {"Content-Type": "application/json"}

}
ip

ip

Returns the IP address of the client who called the HTTP function.

Syntax

get ip(): String

Type

String

Examples

Get the IP from a call to a HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCByZXF1ZXN0SXAgPSByZXF1ZXN0LmlwOyAvLyAiMjU1LjI1NS4yNTUuMjU1IgoKfQo=
// In http-functions.js

export function use_myFunction(request) {

  let requestIp = request.ip; // "255.255.255.255"

}
method

method

Returns the HTTP method used in calling an HTTP function.

Syntax

get method(): String

Description

Returns "GET", "POST", "PUT", or "DELETE".

Type

String

Examples

Get the method used to call the HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBtZXRob2QgPSByZXF1ZXN0Lm1ldGhvZDsgLy8gIkdFVCIKCn0K
// In http-functions.js

export function use_myFunction(request) {

  let method = request.method; // "GET"

}
path

path

Returns the path of the URL used to call an HTTP function.

Syntax

get path(): String[]

Description

Premium sites: Premium site path

Free sites: Free site path

Type

String[ ]

Examples

Get the path of the URL from a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBwYXRoID0gcmVxdWVzdC5wYXRoOyAvLyBbInN1YiJdCgp9Cg==
// In http-functions.js

export function use_myFunction(request) {

  let path = request.path; // ["sub"]

}
query

query

Returns the query fields and values of the URL used to call an HTTP function.

Syntax

get query(): Object

Description

Premium sites: Premium site query

Free sites: Free site query

Type

Object

Examples

Get the query of the URL from a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCBxdWVyeSA9IHJlcXVlc3QucXVlcnk7IC8vIHsicSI6ICJ2YWx1ZSJ9Cgp9Cg==
// In http-functions.js

export function use_myFunction(request) {

  let query = request.query; // {"q": "value"}

}
url

url

Returns the full URL of a call to an HTTP function.

Syntax

get url(): String

Description

Premium sites: Premium site URL

Free sites: Free site URL

Type

String

Examples

Get the URL of a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIGxldCB1cmwgPSByZXF1ZXN0LnVybDsKICAvLyBQcmVtaXVtIHNpdGU6CiAgLy8gImh0dHBzOi8vd3d3LmRvbWFpbi5jb20vX2Z1bmN0aW9ucy9teUZ1bmN0aW9uL3N1Yj9xPXZhbHVlIgogIC8vCiAgLy8gRnJlZSBzaXRlOgogIC8vICJodHRwczovL3VzZXIud2l4LXNpdGVzLmNvbS9teXNpdGUvX2Z1bmN0aW9ucy9teUZ1bmN0aW9uL3N1Yj9xPXZhbHVlIgoKfQo=
// In http-functions.js

export function use_myFunction(request) {

  let url = request.url;
  // Premium site:
  // "https://www.domain.com/_functions/myFunction/sub?q=value"
  //
  // Free site:
  // "https://user.wix-sites.com/mysite/_functions/myFunction/sub?q=value"

}
WixHttpFunctionRequestBody

WixHttpFunctionRequestBody

An object returned by the body property representing the body of a call to an HTTP function.

Properties

text() Promise Returns a Promise which resolves to the body of the call as a string.
json() Promise Returns a Promise which resolves to the body of the call as a JSON object.

Examples

Get the body from a call to an HTTP function

Ly8gSW4gaHR0cC1mdW5jdGlvbnMuanMKCmV4cG9ydCBmdW5jdGlvbiB1c2VfbXlGdW5jdGlvbihyZXF1ZXN0KSB7CgogIHJlcXVlc3QuYm9keS50ZXh0KCkKICAgIC50aGVuKCAoYm9keSkgPT4gewogICAgICBsZXQgcmVxdWVzdEJvZHkgPSBib2R5OwogICAgfSApOwoKfQo=
// In http-functions.js

export function use_myFunction(request) {

  request.body.text()
    .then( (body) => {
      let requestBody = body;
    } );

}