Custom site APIs allow you to expose your site's functionality externally. This means that you, or other people, can access your site's functionality by calling your custom site APIs.
Write and export HTTP functions to define custom site APIs. When you and others call the custom site APIs you defined, the corresponding HTTP function runs and the API responds with the HTTP function's return value.
Custom site APIs are only intended for use in server-to-server communications. For example, don't use cusotm site APIs to set a cookie on a site visitor's browser as you may no longer be in compliance with applicable data privacy regulations.
For example, you might use custom site APIs to:
You can write http functions using:
The main components of an HTTP function are:
HTTP functions support the following HTTP methods:
GET
POST
PUT
DELETE
To learn more, see Methods for HTTP Functions.
The function name is the unique identifier for your HTTP function in your site. It is also used to identify the function in the custom site API call.
The request parameter is an object that is passed to the HTTP function. Use the request parameter for defining the details needed to process the HTTP function when it is called. The details generally include the request body, headers, URL, and other information.
For all supported properties, see WixHttpFunctionRequest
.
Add code inside your HTTP function to run when your custom site API is called.
Inside your HTTP function, you have full access to the full range of Velo APIs and you can import and call functions defined elsewhere on your site.
Your HTTP function should return a response object. This is the response provided by the custom site API when it's called.
There are several functions you can use to create a response object. Find them in the wix-http-functions
module.
Authentication context is information about who is calling an API.
Calling Velo APIs with authentication context allows you to use functions that return different responses based on who calls them, such as getCurrentMember()
.
Depending on whether you need to include authentication context in your request, there are different ways to call your custom site API:
Call your API using the HTTP functions REST API or SDK module. Provide these APIs with your HTTP function's details through the API's parameters and authorization.
You must publish your site for your custom site APIs to be available through these APIs.
Access your custom site APIs with different endpoints depending on the context in which you want to use them:
Learn more about custom site API Calls.