Wix Blocks: Exposing an App API with HTTP Functions

2 min read
All Wix users can create Velo Packages. To create apps for Wix sites with the full version of Wix Blocks, join Wix Studio.

Blocks allows you to create functions to expose the functionality of your app as a service.
You can use it in sites where your app is installed by calling your app's APIs, as defined by the functions you create in the http-functions.js file.

This feature is very similar to exposing site APIs through HTTP functions, but with a slightly different syntax. 

To create HTTP functions:
  1. Click the Public and Backend icon public and backend icon in the Blocks left menu. 
  2. Hover over the add icon in the Backend section. 
  3. Click Expose site API


Clients consume your HTTP functions by reaching endpoints using the following pattern:
  • For premium sites: https:/{user_domain}/_functions/<app_namespace>-backend/<function_name>’?<optional_parameter>’
    Example: https://mysite.com/_functions/@johndoe/exampleapp-backend/multiply?leftOperand=3&rightOperand=4
  • For free sites: https://{user_name}.wixsite.com/{site_name}/_functions/<app_namespace>-backend<function_name>’?<optional_parameter>’
    Example: https://johendoe.wixsite.com/mysite/_functions/@johndoe/exampleapp-backend/multiply?leftOperand=3&rightOperand=4

You can test your HTTP functions by reaching endpoints using the following pattern:
  • For premium sites: https://www.{user_domain}/_functions-dev/<app-namespace>/<functionName>’?<optional_parameter>’
    Example: https://mysite.com/_functions-dev/@johndoe/exampleapp-backend/multiply?leftOperand=3&rightOperand=4
  • For free sites: https://{user_name}.wixsite.com/{site_name}/_functions-dev/<app_namespace>/<function_name>’?<optional_parameter>’
    Example: https://johndoe.wixsite.com/mysite/_functions-dev/@johndoe/exampleapp-backend/multiply?leftOperand=3&rightOperand=4

Did this help?