Documentation / @zerotal/core / index / request
Function: request()
Implementation of the global request helper.
Call Signature
request():
HttpContext
Defined in: helpers/request.ts:19
Retrieves the active HTTP request context from the async execution fiber.
Returns
The current request context.
Throws
If called outside of an active HTTP request lifecycle.
Example
// 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
Retrieves a deeply merged input value from the current request.
Resolution Priority:
- Route parameters (e.g.,
ctx.params['id']) - Parsed body data (e.g., JSON or FormData)
- 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
// Get a value with a fallback
const page = request('page', '1');
// Get a typed value
const id = request<number>('id');