Skip to content

Helpers

Helpers are standalone, tree-shakeable functions for interacting with requests and responses. They keep the core lightweight — unused helpers are excluded from the final bundle.

Request Helpers

HelperDescription
getRequestHeader(event, name)Get a single request header
getRequestHostName(event, options?)Get the request hostname (proxy-aware)
getRequestIP(event, options?)Get the client IP address (proxy-aware)
getRequestProtocol(event, options?)Get the request protocol (proxy-aware)
getRequestAcceptableContentTypes(event)Get all acceptable content types
getRequestAcceptableContentType(event, input?)Get best matching content type
isRequestCacheable(event, modifiedTime)Check if the client cache is still valid
matchRequestContentType(event, type)Check request Content-Type

Response Helpers

HelperDescription
sendFile(event, opts)Send a file with range request support
sendRedirect(event, url, statusCode?)Redirect the client
sendStream(event, stream)Stream data to the client
sendFormat(event, formats)Content-negotiate and send
createEventStream(event, options?)Create a Server-Sent Events stream
setResponseCacheHeaders(event, options?)Set cache-related headers
setResponseHeaderAttachment(event, filename?)Set Content-Disposition attachment
setResponseHeaderInline(event, filename?)Set Content-Disposition inline
setResponseHeaderContentType(event, type)Set Content-Type header
appendResponseHeader(event, name, value)Append to a response header
createContentDisposition(filename?, options?)Build a Content-Disposition header value
parseContentDisposition(header, options?)Parse a Content-Disposition header value

Event Properties

These are accessed directly on the event object, not through helper functions:

PropertyDescription
event.requestThe underlying ServerRequest
event.methodHTTP method (GET, POST, etc.)
event.pathURL path
event.paramsRoute parameters
event.headersRequest headers (Headers object)
event.searchParamsURL search parameters (URLSearchParams)
event.mountPathMount path prefix
event.responseResponse accumulator (status, headers, statusText)
event.dispatchedWhether a response has been produced
event.storePer-request state store for data sharing
event.next()Continue to the next handler (cached)

See the Request and Response guides for detailed usage.