The WixHttpFunctionRequest
object breaks the URL of the incoming call to an HTTP
function into different parameters for easy access.
The URL of the incoming call to an HTTP function is broken into:
For premium sites, the URL of the incoming call has the following format:
https://www.domain.com/_functions/myFunction/sub?q=value
https://www.domain.com/_functions
sub
q=value
For free sites, the URL of the incoming call has the following format:
https://user_name.wixsite.com/mysite/_functions/myFunction/sub?q=value
https://user_name.wixsite.com/mysite/_functions
sub
q=value
Returns the base URL of a call to an HTTP function.
Premium sites:
Free sites:
// In http-functions.js
export function use_myFunction(request) {
let baseUrl = request.baseUrl;
// Premium site: "https://www.domain.com/_functions"
// Free site: "https://user_name.wixsite.com/mysite/_functions"
}
Returns an object representing the body of the incoming call to an HTTP function.
Use the functions of the returned WixHttpFunctionRequestBody
object to get the body in a number of formats.
The request body can be a maximum of 512kb.
// In http-functions.js
export function use_myFunction(request) {
request.body.text().then((body) => {
let requestBody = body;
});
}
Returns the function name of a call to an HTTP function.
Premium sites:
Free sites:
// In http-functions.js
export function use_myFunction(request) {
let functionName = request.functionName; // myFunction
}
Returns the HTTP header fields used in a call to an HTTP function.
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.
// In http-functions.js
export function use_myFunction(request) {
let headers = request.headers;
// {"content-type": "application/json"}
}
Returns the IP address of the client who called the HTTP function.
// In http-functions.js
export function use_myFunction(request) {
let requestIp = request.ip; // "255.255.255.255"
}
Returns the HTTP method used in calling an HTTP function.
Returns "GET"
, "POST"
, "PUT"
, or "DELETE"
.
// In http-functions.js
export function use_myFunction(request) {
let method = request.method; // "GET"
}
Returns the path of the URL used to call an HTTP function.
Premium sites:
Free sites:
// In http-functions.js
export function use_myFunction(request) {
let path = request.path; // ["sub"]
}