Raw Functions
Last updated
Last updated
For simplicity, default UbiFunctions won't allow you to use customized response codes, or use a Content-type
header different than application/json
.
But what if your application needs such level of customization? This is why Raw functions exists. It allows you to:
Capture the entire path inside the function, allowing you to use custom endpoint paths in addition to the UbiFunction’s native. This allows executing different routines based on the endpoint path.
Receive and respond custom headers. For instance, Authorization headers.
Set custom response codes 20X, 40X, 50X, beyond the standard 200 in UbiFunctions. This allows the HTTP client to know the exact result of the execution.
Receive and respond custom Content-Type headers for the request body and response: application/json, plain/text, etc.
To enable Raw functions, just toggle the option in the left-side settings section of the UbiFunction.
Once enabled, the “args“ object received in the UbiFunction’s main function will follow the below structure:
Where:
Key | Type | Description |
path | string | UbiFunction Path. For example: |
headers | object | Key-value object containing all the headers of the request. |
body | string | Body of the request |
Note that the UbiFunction basic URL structure should remain intact, otherwise, the request will point to a different UbiFunction.
When a default UbiFunction finishes, the default response will be a 200 status code if everything went okay, or a 4xx if the execution broke at some point. However, with Raw functions, you can customize the response code, body, and headers. That way, the HTTP client making the request will know the precise result of the execution.
The following is the JSON structure to customize the response:
Where:
Key | Type | Description |
status_code | int | Status codes to indicate whether the UbiFunction request has been successfully completed. |
headers | object | Key-value object containing headers of the response. Default value: {"Content-Type": "application/json"} |
body | string | Formatted based on the Content-Type header. |
To learn more, please refer to the following guide: