[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/core](../../README) / [index](../README) / request

# Function: request()

Implementation of the global request helper.

## Call Signature

> **request**(): [`HttpContext`](../classes/HttpContext)

Defined in: [helpers/request.ts:19](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/request.ts#L19)

Retrieves the active HTTP request context from the async execution fiber.

### Returns

[`HttpContext`](../classes/HttpContext)

The current request context.

### Throws

If called outside of an active HTTP request lifecycle.

### Example

```ts
// Access the full context
const ctx = request();
const token = ctx.bearerToken();
```

## Call Signature

> **request**\<`T`\>(`key`, `fallback?`): `T` \| `undefined`

Defined in: [helpers/request.ts:44](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/request.ts#L44)

Retrieves a deeply merged input value from the current request.

**Resolution Priority:**
1. Route parameters (e.g., `ctx.params['id']`)
2. Parsed body data (e.g., JSON or FormData)
3. Query string parameters (e.g., `?page=2`)

⚠️ **Note:** Body resolution is synchronous. It will only find body data if it
has already been parsed and cached (e.g., via a `FormRequest` or `await ctx.body()`).

### Type Parameters

#### T

`T` = `string`

The expected return type of the input value.

### Parameters

#### key

`string`

The name of the input field to resolve.

#### fallback?

`T`

An optional default value to return if the key is missing.

### Returns

`T` \| `undefined`

The resolved input value, the fallback, or undefined.

### Example

```ts
// Get a value with a fallback
const page = request('page', '1');

// Get a typed value
const id = request<number>('id');
```
