BCMS Functions
BCMS Functions are JavaScript functions that you can execute by sending an
HTTP request to the back end API. Once you create a function, it will be
available at POST: https://{CMS_DOMAIN}/api/function/{FUNCTION_NAME}
.
To create simple functions that fit into one .ts file, you can follow the instructions below. For more complex functions, or when you want to benefit autocomplete, split it into several files, services etc., you can code your functions locally.
Adding a function
log in to the BCMS Cloud and open the instance you would like to add a function to. Click on the Functions card. From here, click on Add new function button where you can provide a few things:
- Function name - the name of the function, as string. Keep in mind
in mind that the name will be slugified. For example, if the name is Test function,
it will becomes
test-function
. - Access to function - Can be Public or Private. Public function will be accessible to anyone while private function will require API Key authorization.
- Global scope - The place where you want to do your imports and declare utility functions.
- Handler scope - The code which will be called when endpoint of the function
is called. Here you have access to:
request
,errorHandler
,logger
andauth
objects. More information here
When you add a function, CMS will rebuild with new configuration. It'll take a few seconds.
Editing a function
When you are on the instance page click on Functions card. To edit a function, click on Edit button.
When you edit a function, CMS will rebuild with new configuration. It'll take a few seconds.
Deleting a function
Click on Functions card on the instance page. To delete a function, click on Edit button and then Delete.
When you delete a function, CMS will rebuild with new configuration. It'll take a few seconds.