# Raw Functions

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.

<figure><img src="/files/cp6wG8VDPI4xlFNyb9K5" alt=""><figcaption></figcaption></figure>

### args Object

Once enabled, the “args“ object received in the UbiFunction’s main function will follow the below structure:

```
{
    "path": string,
    "headers": object, 
    "body": string,
}
```

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                                         |

Note that the UbiFunction basic URL structure should remain intact, otherwise, the request will point to a different UbiFunction.

### Response codes

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:

```
{
 "status_code": int,
 "headers": object, 
 "body": string, 
}
```

Where:

| Key          | Type   | Description                                                                                                                             |
| ------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| status\_code | int    | Status codes to indicate whether the UbiFunction request has been successfully completed.                                               |
| headers      | object | <p>Key-value object containing headers of the response.<br><br><strong>Default value</strong>: {"Content-Type": "application/json"}</p> |
| body         | string | Formatted based on the Content-Type header.                                                                                             |

To learn more, please refer to the following guide:

{% embed url="<https://help.ubidots.com/en/articles/4936503-ubifunctions-using-raw-functions>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ubidots.com/ubifunctions/advanced/raw-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
