HTTP Decorators
Define TypeScript HTTP endpoints, route parameters, query parameters, request bodies, headers, file uploads, SSE streams, status codes, and redirects with AxilJS semantic decorators.
HTTP Decorators
AxilJS HTTP decorators define the HTTP contract of an operation without coupling application code to a specific web framework or router.
They describe:
- HTTP methods and routes
- Path and query parameters
- Request bodies
- Headers and cookies
- File uploads
- Server-Sent Events (SSE)
- Response status codes
- Redirects
The HTTP runtime reads this metadata and maps it to the underlying server implementation.
@tHttp
@tHttp declares an HTTP endpoint.
AxilJS uses a single HTTP decorator instead of separate decorators such as @Get(), @Post(), or @Delete().
Options
| Option | Type | Description |
|---|---|---|
method | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'ALL' | HTTP method |
path | string | Endpoint path. Supports :param segments |
version | string | API version |
prefix | string | Route prefix override |
For example:
The HTTP consumer can expose this as a versioned endpoint such as /v2/users.
@tParam
@tParam binds a URL path parameter to a handler argument.
Use it when a value is part of the resource path.
For example:
Here, userId is 42 and postId is 100.
@tQuery
@tQuery binds a query-string parameter to a handler argument.
For a request such as:
the parameters are available directly through the decorated arguments.
@tBody
@tBody binds the request body to a handler argument.
Use it for complete request DTOs:
It can also bind a specific field:
@tHeader
@tHeader binds a request header to a handler argument.
This is useful for values such as:
- Authorization tokens
- Tenant identifiers
- Correlation IDs
- Custom client headers
@tCookie
@tCookie binds a cookie value.
The application receives the selected cookie without depending directly on the underlying HTTP request object.
@tFile
@tFile declares a file upload and its constraints.
Options
| Option | Type | Description |
|---|---|---|
maxSize | number | Maximum file size in bytes |
mimeTypes | string[] | Allowed MIME types |
required | boolean | Whether a file is required |
multiple | boolean | Whether multiple files are accepted |
The upload constraints remain part of the endpoint metadata and can be consumed by the HTTP layer.
@tSse
@tSse marks an HTTP endpoint as a Server-Sent Events (SSE) stream.
This allows the HTTP runtime to treat the endpoint as a streaming response rather than a standard request-response operation.
Typical use cases include:
- Live notifications
- Progress updates
- AI response streaming
- Real-time application events
- Long-running operation status
@tStatus
@tStatus explicitly defines the HTTP response status code.
For a successful deletion:
This keeps response semantics explicit in the endpoint declaration.
@tRedirect
@tRedirect declares a redirect response.
The decorator defines both the redirect destination and HTTP status.
Composing HTTP Decorators
HTTP decorators can be combined with semantic decorators from other AxilJS domains.
For example:
Each decorator represents a separate concern:
| Decorator | Concern |
|---|---|
tHttp | HTTP endpoint |
tAuth | Authentication |
tRateLimit | Request rate control |
tTransaction | Database transaction |
tAudit | Audit event |
tStatus | HTTP response status |
tBody | Request body binding |
The decorators do not need to know about one another. Each writes its semantic metadata to the AxilJS metadata registry, where the appropriate consumer can process it.
HTTP Metadata and Consumers
The HTTP metadata can be consumed by different parts of the AxilJS ecosystem.
For example:
This keeps the HTTP contract separate from the implementation of the underlying router.
Complete Example
A complete endpoint can combine route declaration, request parameters, authentication, rate limiting, transactions, auditing, and response semantics:
The endpoint declaration communicates the HTTP contract and its operational requirements without introducing framework-specific controller or route classes.
HTTP Decorator Reference
| Decorator | Purpose |
|---|---|
tHttp | Declare an HTTP endpoint |
tParam | Bind a path parameter |
tQuery | Bind a query parameter |
tBody | Bind request body data |
tHeader | Bind a request header |
tCookie | Bind a cookie |
tFile | Bind and constrain file uploads |
tSse | Declare an SSE endpoint |
tStatus | Define the HTTP response status |
tRedirect | Define a redirect response |