Raw functions

For simplicity, default UbiFunctions do not let you use custom response codes or a Content-Type header other than application/json.

But what if your application needs this level of customization? This is why Raw functions exist. They let you:

  • Capture the entire path inside the function, allowing you to use custom endpoint paths in addition to the UbiFunction’s native path. This lets you execute different routines based on the endpoint path.

  • Receive and return custom headers. For example, Authorization headers.

  • Set custom response codes such as 2xx, 4xx, and 5xx beyond the standard 200 in UbiFunctions. This lets the HTTP client know the exact result of the execution.

  • Receive and return custom Content-Type headers for the request body and response, such as application/json or text/plain.

To enable Raw functions, toggle the option in the left-side settings section of the UbiFunction.

args Object

Once enabled, the args object received in the UbiFunction’s main function follows this structure:

Where:

Key
Type
Description

path

string

UbiFunction path. For example: /prv/<function-name>/

headers

object

Key-value object containing all the headers of the request.

body

string

Body of the request

The base UbiFunction URL structure must remain intact. Otherwise, the request points to a different UbiFunction.

Response codes

When a default UbiFunction finishes, it returns a 200 status code if everything goes well, or a 4xx code if the execution fails. However, with Raw functions, you can customize the response code, body, and headers. This way, the HTTP client making the request knows the precise result of the execution.

Use the following 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.

For more information, see:

Last updated

Was this helpful?