> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getpostchi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Functions

> Use built-in functions inline in your request files to transform values, encode credentials, and read files from disk.

Functions let you transform values directly inside a request file without preprocessing. You call them inline using the syntax:

```
functionName(arg1, arg2)
```

Arguments can be literal strings or variables: `bearer(<api_token>)`.

***

## Built-in functions

### `bearer(token)`

Produces a `Bearer <token>` string. Use it in the `Authorization` header instead of writing the prefix manually.

```http theme={null}
GET https://api.example.com/users
Authorization: bearer(<api_token>)
```

Resolves to `Authorization: Bearer abc123` when `api_token=abc123` in your environment.

***

### `basicAuth(username, password)`

Encodes the username and password as a Base64 `Basic` credential string. Use it in the `Authorization` header.

```http theme={null}
POST https://api.example.com/login
Authorization: basicAuth(<username>, <password>)
```

Resolves to `Authorization: Basic dXNlcjpwYXNz` (the Base64 encoding of `user:pass`).

***

### `join(...parts)`

Concatenates any number of strings and variables together with no separator.

```http theme={null}
GET https://api.example.com/report
X-Correlation-Id: join(req-, <user_id>, -, <session_id>)
```

Resolves to `X-Correlation-Id: req-42-abc` when `user_id=42` and `session_id=abc`.

***

### `readText(path)`

Reads a file from disk and inlines its content as the request body. Useful for large JSON payloads or other text content you want to keep in a separate file.

```http theme={null}
POST https://api.example.com/events
Content-Type: application/json
@body
readText(/path/to/body.json)
```

***

### `readFile(path)`

Reads a binary file from disk and attaches it as a form part in a multipart body. This function is only valid inside a form body — see [Request body](/requests/body) for usage.

<Note>
  `readFile` is used in `@body` form entries, not in headers. Using `readFile` in a form body automatically switches the content type to `multipart/form-data` if you haven't set it explicitly.
</Note>

***

## Example: authenticated request with functions

```http theme={null}
// Create a new user
POST https://api.example.com/users
Authorization: bearer(<api_token>)
Content-Type: application/json
X-Request-Id: join(user-create-, <user_id>)
@body
{
  "name": "<username>",
  "role": "member"
}
```

This single request uses `bearer()` to format the token, `join()` to build a custom header value, and a variable inside a JSON body — all resolved at run time from the active environment.
