Request Helpers
All request helpers take an IRoutupEvent as the first argument.
Headers & Content Negotiation
getRequestHeader
Get a single request header by name.
declare function getRequestHeader(
event: IRoutupEvent,
name: string,
): string | null;const auth = getRequestHeader(event, 'authorization');matchRequestContentType
Check whether the request's Content-Type matches the given type.
declare function matchRequestContentType(
event: IRoutupEvent,
type: string,
): boolean;if (matchRequestContentType(event, 'application/json')) {
// handle JSON
}getRequestAcceptableContentTypes
Return all content types the client accepts, from the Accept header.
declare function getRequestAcceptableContentTypes(
event: IRoutupEvent,
): string[];getRequestAcceptableContentType
Return the best matching content type from the Accept header, optionally filtered against a list of candidates.
declare function getRequestAcceptableContentType(
event: IRoutupEvent,
input?: string | string[],
): string | undefined;const type = getRequestAcceptableContentType(event, [
'application/json',
'text/html',
]);getRequestAcceptableCharsets
Return all acceptable charsets from the Accept-Charset header.
declare function getRequestAcceptableCharsets(
event: IRoutupEvent,
): string[];getRequestAcceptableCharset
Return the best matching charset from the Accept-Charset header.
declare function getRequestAcceptableCharset(
event: IRoutupEvent,
input: string | string[],
): string | undefined;getRequestAcceptableEncodings
Return all acceptable encodings from the Accept-Encoding header.
declare function getRequestAcceptableEncodings(
event: IRoutupEvent,
): string[];getRequestAcceptableEncoding
Return the best matching encoding from the Accept-Encoding header.
declare function getRequestAcceptableEncoding(
event: IRoutupEvent,
input: string | string[],
): string | undefined;getRequestAcceptableLanguages
Return all acceptable languages from the Accept-Language header.
declare function getRequestAcceptableLanguages(
event: IRoutupEvent,
): string[];getRequestAcceptableLanguage
Return the best matching language from the Accept-Language header.
declare function getRequestAcceptableLanguage(
event: IRoutupEvent,
input?: string | string[],
): string | undefined;Network
getRequestHostName
Get the hostname from the request, respecting proxy headers when configured.
declare function getRequestHostName(
event: IRoutupEvent,
options?: RequestHostNameOptions,
): string | undefined;const host = getRequestHostName(event, { trustProxy: true });getRequestIP
Get the client IP address. Uses the srvx runtime value when available, falling back to X-Forwarded-For header inspection when trustProxy is enabled.
declare function getRequestIP(
event: IRoutupEvent,
options?: RequestIpOptions,
): string | undefined;const ip = getRequestIP(event, { trustProxy: true });getRequestProtocol
Get the request protocol (http or https), respecting proxy headers when configured.
declare function getRequestProtocol(
event: IRoutupEvent,
options?: RequestProtocolOptions,
): string;const proto = getRequestProtocol(event, { trustProxy: true });Cache
isRequestCacheable
Check the If-Modified-Since header against a modification time. Returns true if the client's cached version is still valid.
declare function isRequestCacheable(
event: IRoutupEvent,
modifiedTime: string | Date,
): boolean;if (isRequestCacheable(event, stats.mtime)) {
return new Response(null, { status: 304 });
}Per-Request State
Use event.store directly to share data between handlers. There are no helper functions for this — it is a plain Record<string | symbol, unknown>:
// Set a value
event.store.userId = 42;
event.store[Symbol.for('myPlugin:data')] = { role: 'admin' };
// Read a value
const userId = event.store.userId;
// Delete a value
delete event.store.userId;Use symbol keys (e.g., Symbol.for('routup:body')) to avoid collisions between plugins.