Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/http/server.ts>RequestContext

A JavaScript extension package for building strong and modern applications.
Latest
interface RequestContext
import { type RequestContext } from "https://deno.land/x/ayonli_jsext@v0.9.72/http/server.ts";

Represents the context of an HTTP request. It provides additional information about the request and allows for upgrading the connection to a WebSocket.

Properties

remoteAddress: NetAddress | null

The remote address of the client. This property may not be available in worker environments (such as Cloudflare Workers) or when the server is started via deno serve.

optional
waitUntil: ((promise: Promise<unknown>) => void) | undefined

Prolongs the request's lifetime until the promise is resolved. Only available in workers environments such as Cloudflare Workers.

optional
bindings: { [x: string]: any; __STATIC_CONTENT?: KVNamespace; } | undefined

The bindings of the request, only available in Cloudflare Workers.

Methods

createEventEndpoint(): { events: EventEndpoint<Request>; response: Response; }

Creates an SSE (server-sent events) endpoint for sending events to the client.

upgradeWebSocket(): { socket: WebSocketConnection; response: Response; }

Upgrades the request to a WebSocket connection.

time(name: string, description?: string): void

Starts a timer that can be used to compute the duration of an operation identified by a unique name. When the operation completes, call timeEnd() with the same name to stop the timer.

This function is similar to the console.time, except it logs the duration to the Server-Timing header of the response and will be displayed in the browser's devtools.

Optionally, we can provide a description that will be used as the title when displaying the timing metrics.

We could use a total label to measure the total time spent, which has special meaning in the Google Chrome browser. However, it may not be accurate since multiple operations can happen at the same time concurrently.

timeEnd(name: string): void

Stops a timer that was previously started by calling time() with the same name.