Classes

@system-inc/base-foundation · 515c140 · 3 symbols

Class for creating common HTTP responses.

Members

  • static fromError(error: BaseError, responseInit?: ResponseInit): Response

    Creates a Response from a BaseError.

    This response will be the same as if the BaseError was thrown, however it will not produce a stack trace in the logs, indicating that this was an expected error condition, which may be desired.

  • static fromJson(json: unknown, responseInit?: ResponseInit): Response

    Creates a Response from a JSON object.

  • static noContent(responseInit?: ResponseInit): Response

    Creates a status 204 No Content with null response body (required for no-content).

  • static ok(responseInit?: ResponseInit): Response

    Creates a empty response with status 200 OK.

    This is used to signal a successful request or server processing to the client when no response body is required, desired or necessary.

  • static redirect(url: string | URL, status: HttpRedirectStatusCode): Response

    Creates a redirect Response.

View source ↗

A branded key for type-safe extension storage on RequestContext.

Modules create keys to store and retrieve per-request data without stringly-typed lookups:

// Module defines the key
const DeviceId = RequestContextKey.create<string>('deviceId');

// Middleware sets it
rc.set(DeviceId, '123');

// Application reads it — fully typed
const id = rc.get(DeviceId); // string | undefined

Extends TypedKey with the 'request-context' scope brand so request-context keys cannot be confused with environment, module, or WebSocket keys at the type level.

Two keys with the same name would collide on the underlying per-request Map and silently overwrite each other. create enforces uniqueness at creation time and throws on duplicates, so the failure surfaces at module load rather than as mysterious read-wrong-value bugs at runtime. Define each key once at module scope and import it where needed.

extends TypedKey<T, "request-context">

Members

  • _brand: T

    phantom type brand — never assigned at runtime

  • _scope: "request-context"

    phantom scope brand — never assigned at runtime

  • name: string

  • static create(name: string): RequestContextKey<T>

    Creates a typed extension key for storing per-request data.

    Throws if a RequestContextKey with the same name has already been created.

View source ↗

Members

  • acceptLanguageHeader: string | undefined

  • city: string | undefined

  • country: string | undefined

  • languagePreferences: readonly LanguagePreference[]

  • latitude: string | undefined

  • longitude: string | undefined

  • region: string | undefined

  • timeZone: string | undefined

  • locale: { languageCode?: string; timezone?: string }

  • location: string

  • preferredLanguage: string | undefined

View source ↗