use( )
A function that responds to requests made with any HTTP method.
Description
Requests made with any of the GET, POST, PUT, DELETE, or OPTIONS HTTP methods will be routed to this function unless another function is defined specifically for the request's HTTP method.
For example, if you create functions named get_myFunction
and
use_myFunction
, GET calls to myFunction will be handled by
get_myFunction
, while POST, PUT, DELETE, and OPTIONS calls will be handled by
use_myFunction
.
The use()
function is not a function that you call from your code. You define
the function in a file named http-functions.js in your site's Backend section.
The function is called when your users make HTTP requests using the associated
URLs as described below.
All GET, POST, PUT, DELETE, and OPTIONS HTTP requests with the following URL will be routed to this function unless another function is defined specifically for the request's HTTP method:
Premium sites:
Copy Codehttps://www.{user_domain}/_functions/<functionName>
Free sites:
Copy Codehttps://{user_name}.wixsite.com/{site_name}/_functions/<functionName>
Respond to the request by returning a WixHttpFunctionResponse
object you create using one of the response()
,
ok()
, created()
,
notFound()
, serverError()
,
badRequest()
, or forbidden()
functions.
Note: You must publish your site at least once before using both the testing and production endpoints. After that, you save your site for changes you make to testing endpoints to take effect and you publish your site for changes you make to the production endpoints to take effect.
Syntax
function use(request: wixhttpfunctionrequest-obj): WixHttpFunctionResponse
use Parameters
NAME
TYPE
DESCRIPTION
Returns
Return Type:
Was this helpful?
Create a catchall HTTP function
This example creates a catchall HTTP function named myFunction.
1// In http-functions.js23import {ok} from 'wix-http-functions';45export function use_myFunction(request) {67 const method = request.method;89 // ...1011 return ok();12}13