About Custom Site APIs

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.

Important:

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:

  • Integrate your site with an automation tool, such as Zapier or IFTTT.
  • Receive notifications or information from external webhooks or services.
  • Share a backend between your site and another application.

Supported IDEs

You can write http functions using:

  • The editor (Wix Studio and Wix Editor).
  • The Wix IDE (Wix Studio).
  • Your local IDE (Wix Studio and Wix Editor).

HTTP functions

The main components of an HTTP function are:

Copy

HTTP method

HTTP functions support the following HTTP methods:

  • GET
  • POST
  • PUT
  • DELETE

To learn more, see Methods for HTTP Functions.

Function name

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.

Request parameter

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.

Functionality

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.

Response object

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

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:

With authentication context

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.

Without authentication context

Access your custom site APIs with different endpoints depending on the context in which you want to use them:

  • Test sites
  • Sites being built with git integration
  • Latest code in the editor
  • Production

Learn more about custom site API Calls.

See also

Was this helpful?
Yes
No