CorvidReference

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
baseUrlpathquery
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
baseUrlpathquery
https: //user.wixsite.com/mysite/_functions/myFunction/sub?q=value

Table of Contents

PROPERTIES

?
Store values associated with an object.
baseUrlReturns the base URL of a call to an HTTP function.
bodyReturns an object representing the body of the incoming call to an HTTP function.
functionNameReturns the function name of a call to an HTTP function.
headersReturns the HTTP header fields used in a call to an HTTP function.
ipReturns the IP address of the client who called the HTTP function.
methodReturns the HTTP method used in calling an HTTP function.
pathReturns the path of the URL used to call an HTTP function.
queryReturns the query fields and values of the URL used to call an HTTP function.
urlReturns the full URL of a call to an HTTP function.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
WixHttpFunctionRequestBodyAn object returned by the body property representing the body of a call to an HTTP function.

baseUrl

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

Description

Premium sites:

Free sites:

Syntax

get baseUrl(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the base URL of a call to an HTTP function

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

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

Description

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

Syntax

get body(): WixHttpFunctionRequestBody

Examples

Get the body from a call to an HTTP function

// In http-functions.js

export function use_myFunction(request) {

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

}

functionName

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

Description

Premium sites:

Free sites:

Syntax

get functionName(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the function name of a call to an HTTP function

// In http-functions.js

export function use_myFunction(request) {

  let functionName = request.functionName; // myFunction

}

headers

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

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.

Headers are returned in lowercase, regardless of how they were sent by the function caller.

Syntax

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

Examples

Get the headers from a call to an HTTP function

// In http-functions.js

export function use_myFunction(request) {

  let headers = request.headers;
  // {"content-type": "application/json"}

}

ip

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

Syntax

get ip(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the IP from a call to a HTTP function

// In http-functions.js

export function use_myFunction(request) {

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

}

method

Returns the HTTP method used in calling an HTTP function.

Description

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

Syntax

get method(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the method used to call the HTTP function

// In http-functions.js

export function use_myFunction(request) {

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

}

path

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

Description

Premium sites:

Free sites:

Syntax

get path(): Array<string>
TYPE
?
The kind of data the property stores.
Array<string>

Examples

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

// In http-functions.js

export function use_myFunction(request) {

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

}

query

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

Description

Premium sites:

Free sites:

Syntax

get query(): Object
TYPE
?
The kind of data the property stores.
Object

Examples

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

// In http-functions.js

export function use_myFunction(request) {

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

}

url

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

Description

Premium sites:

Free sites:

Syntax

get url(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the URL of a call to an HTTP function

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

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

Syntax

type WixHttpFunctionRequestBody = {
  text(): Promise<string>
  json(): Promise<Object>
}
MEMBERS
?
The properties of an object.
text()
Promise<string>
Returns a Promise which resolves to the body of the call as a string.
json()
Promise<Object>
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

// In http-functions.js

export function use_myFunction(request) {

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

}