Ctx interface represents the HTTP request and response context. It provides methods for accessing request data, sending responses, and managing the request lifecycle.
Type Definition
Core Methods
App
Returns the App instance.Returns the Fiber app reference.
Example
Context
Returns a standard context.Context.Returns a context.Context instance safe for async operations.
Example
SetContext
Set a custom context.Context.The context to associate with the request.
Request Methods
Params
Get route parameters.The parameter name.
Default value if parameter doesn’t exist.
Returns the parameter value.
Example
Query
Get query string parameters.The query parameter name.
Default value if parameter doesn’t exist.
Returns the query parameter value.
Example
Queries
Get all query parameters as a map.Returns all query parameters.
Body
Get the request body (with decompression).Returns the decompressed request body.
Example
BodyRaw
Get the raw request body (without decompression).Returns the raw request body.
Bind
Get the Bind helper for request parsing.Returns the Bind helper instance.
Example
Headers
Get
Get a request header value.The header name (case-insensitive).
Default value if header doesn’t exist.
Returns the header value.
Example
GetReqHeaders
Get all request headers.Returns all request headers.
Cookies
Get a cookie value.The cookie name.
Default value if cookie doesn’t exist.
Returns the cookie value.
Request Information
Method
Get or override the HTTP method.Optional method to override.
Returns the HTTP method.
Path
Get or override the request path.Optional path to override.
Returns the request path.
Protocol
Get the protocol (http or https).Returns “http” or “https”.
Secure
Check if the connection is TLS.Returns true if TLS connection.
IP
Get the remote IP address.Returns the client IP address.
IPs
Get IP addresses from X-Forwarded-For header.Returns array of IP addresses.
Host
Get the host with port.Returns the hostname with port.
Hostname
Get the hostname without port.Returns the hostname.
Port
Get the remote port.Returns the port number.
BaseURL
Get the base URL (protocol + host).Returns the base URL.
OriginalURL
Get the original request URL.Returns the original URL with query string.
FullURL
Get the full request URL.Returns the complete URL.
Response Methods
Status
Set the response status code.The HTTP status code.
Returns the context for chaining.
Example
SendString
Send a string response.The string to send.
Returns an error if send fails.
SendStatus
Send only a status code.The HTTP status code.
Returns an error if send fails.
JSON
Send a JSON response.The data to serialize as JSON.
Returns an error if serialization or send fails.
Example
XML
Send an XML response.The data to serialize as XML.
Returns an error if serialization or send fails.
Send
Send a byte response.The bytes to send.
Returns an error if send fails.
SendFile
Send a file as response.The file path to send.
Enable compression (default: true).
Returns an error if file send fails.
Redirect
Get the redirect helper.Returns the Redirect helper instance.
Example
Headers & Cookies (Response)
Set
Set a response header.The header name.
The header value.
Append
Append a value to a response header.The header name.
The value to append.
Cookie
Set a cookie.The cookie to set.
Example
ClearCookie
Clear a cookie.Cookie names to clear. If omitted, clears all cookies.
Route & Locals
Route
Get the current route.Returns the matched route.
Locals
Store or retrieve local values.The key to store/retrieve.
The value to store.
Returns the stored value.
Example
Control Flow
Next
Execute the next handler in the stack.Returns an error from the next handler.
Example
RestartRouting
Restart routing from the first handler.Returns an error if routing fails.
Content Negotiation
Accepts
Check if the client accepts a content type.Content types or extensions to check.
Returns the best match or empty string.
AcceptsJSON
Check if the client accepts JSON.Returns true if JSON is accepted.
AcceptsHTML
Check if the client accepts HTML.Returns true if HTML is accepted.
AcceptsXML
Check if the client accepts XML.Returns true if XML is accepted.
Utilities
Is
Check the Content-Type.The content type or extension to check.
Returns true if content type matches.
IsJSON
Check if Content-Type is JSON.Returns true if JSON.
IsForm
Check if Content-Type is form-encoded.Returns true if form-encoded.
Fresh
Check if the response is fresh.Returns true if response is still fresh.
Stale
Check if the response is stale.Returns true if response is stale.
XHR
Check if request is XMLHttpRequest.Returns true if XHR request.