context, and the incoming HTTP request lives on context.request. It is an HttpRequest instance (implementing the IRequest interface) that wraps the native Request and exposes the parsed pieces you actually need: the URL, the method, the headers, the query string, the route params, the decoded body, the client IP, the detected locale, and any uploaded files. The framework builds it for you from the native request before the controller runs, so you never construct one by hand — you read it.
For the values you reach for most, the context also carries convenience accessors that point straight at the request: context.params, context.queries, and context.payload are the same objects as context.request.params, context.request.queries, and context.request.payload.
Why this object
- One parsed surface. The native
Requestgives you a raw URL string and aHeadersbag.IRequesthands you a parsedIUrl, a typedqueriesrecord, routeparams, and the decodedpayload— no re-parsing in every controller. - Typed by config.
IRequest<Config>is generic overparams,payload, andqueries, so a controller can declare the exact shape it expects and read it type-safely. - Headers, decoded.
request.headeris a richHeaderobject with helpers for content type, auth, cookies, IP, and a parseduserAgent. - Locale out of the box. The request resolves a
langfrom the query string, a custom header, orAccept-Language— ready for translation without extra work. - Files as first-class. Multipart uploads are parsed into
IRequestFileinstances onrequest.files, each with size, type, format detection, read methods, and awriteto disk.
How it works
The framework reads the nativeRequest, extracts route params from the matched route and the decoded body, then constructs the HttpRequest. During construction it parses the URL (path, host, queries), normalizes the method, wraps the headers, parses the user agent, builds a RequestFile for every uploaded file, and resolves the locale.
| Source | Becomes |
|---|---|
request.url string | url (an IUrl), path, host, queries |
request.method | method (uppercased HttpMethodType) |
request.headers | header (a Header) and userAgent |
| Matched route | params (route parameters) |
| Decoded body | payload (JSON / form fields) |
Multipart FormData | form and files (each an IRequestFile) |
lang/locale query, X-Custom-Lang, Accept-Language | lang (a LocaleInfoType) |
Properties and methods
context.request exposes these read-only members:
| Member | Type | Description |
|---|---|---|
native | Readonly<Request> | The underlying native Request. |
url | IUrl | Parsed URL with helpers (getPath, getQuery, getQueries, getHostname, …). |
path | string | The URL path, e.g. /users/123. |
method | HttpMethodType | Uppercased HTTP method, e.g. GET, POST. |
host | string | Host from the Host header (empty string if absent). |
ip | string | null | Client IP address, if provided. |
header | Header | Header accessor with typed convenience getters. |
userAgent | IUserAgent | null | Parsed user agent (browser, engine, os, device, cpu). |
params | Config["params"] | Route parameters from the matched route. |
queries | Config["queries"] | Query string parameters as a record. |
payload | Config["payload"] | Decoded request body (JSON object or form fields). |
form | FormData | null | Raw multipart form data, when present. |
files | Record<string, IRequestFile> | Uploaded files keyed by form field name. |
lang | LocaleInfoType | Detected locale { code, region }. |
Reading query and route params
Route params come from the dynamic segments of the matched route (/users/:id). Query params come from the URL query string (?page=2&search=alice). Read them from the request, or from the context.params / context.queries shortcuts.
Reading the payload
ForPOST, PUT, and PATCH requests the decoded body is on payload (and mirrored on context.payload). For JSON requests it is the parsed object; for form submissions it is the field record.
Headers and user agent
request.header is a Header object. Use get(name) and has(name) for raw values, or the typed convenience getters for common headers.
IUserAgent with browser, engine, os, device, and cpu. It is null when no User-Agent header is present.
File uploads
When the request is multipart form data, the framework parses it intorequest.form (the raw FormData) and request.files — a record keyed by form field name where each value is an IRequestFile. A RequestFile wraps the native File and adds metadata, format detection, read methods, and disk writing.
RequestFile API
| Member | Type | Description |
|---|---|---|
id | string | Unique 25-character identifier. |
name | string | Generated collision-safe name, {id}.{extension}. |
originalName | string | Original name, kebab-cased, extension preserved. |
type | MimeType | MIME type with charset stripped. |
size | number | Size in bytes. |
extension | string | Lowercased file extension. |
isImage / isSvg / isVideo / isAudio | boolean | Media format detection. |
isPdf / isText / isExcel / isCsv / isJson / isXml / isHtml | boolean | Document format detection. |
readAsArrayBuffer() | Promise<ArrayBuffer> | Read the contents as an ArrayBuffer. |
readAsStream() | ReadableStream<Uint8Array> | Stream the contents (for large files). |
readAsText() | Promise<string> | Read the contents as text. |
write(path) | Promise<void> | Write the file to disk at path. |
Language and locale detection
Every request resolves alang ({ code, region }) during construction, with a fixed precedence:
| Priority | Source | Example |
|---|---|---|
| 1 | lang query parameter | ?lang=fr |
| 2 | locale query parameter | ?locale=de |
| 3 | X-Custom-Lang header | X-Custom-Lang: es |
| 4 | Accept-Language header | Accept-Language: en-US,en;q=0.9 |
region is null and only code is set. When it falls back to Accept-Language, the first language is parsed into code and region (e.g. { code: "en", region: "US" }). If nothing matches, it defaults to en-US.
Best practices
- Prefer the shortcuts. Read
context.params,context.queries, andcontext.payloadfor everyday access; reach forcontext.requestfor headers, IP, files, and locale. - Type the request. Declare a
ConfigforIRequest<Config>(or cast) soparams,queries, andpayloadare checked, notany. - Validate before you trust. Query and body values are user input — run them through Validation before acting on them.
- Never mutate. Every member of
IRequestis read-only; build your reply oncontext.response, not by changing the request. - Use the safe file name. Save uploads under
file.name(the generated, collision-safe name), not the user-suppliedoriginalName, and checksizeand theis*flags before writing. - Let locale flow. Read
request.langrather than re-parsingAccept-Languageyourself; it already applies the documented precedence.
Related
- Controllers — where the request reaches your handler via
context. - Validation — validate
params,queries, andpayloadbefore use. - Response — build the reply with
context.response. - Storage — persist uploaded files beyond a single request.