Expose a Blocks App API with HTTP Functions
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:
- Click the Public and Backend icon
in the Blocks left menu.
- Hover over the
icon in the Backend section.
- Click Expose site API.
Endpoints
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