Askr documentation
Generated API snapshot

@askrjs/server/http

Exports from the declarations published in @askrjs/server. Signatures reflect the published artifact.

Exports

This entrypoint publishes 33 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.

acceptedtype

accepted: (value?: JsonValue, init?: ResponseInit) => Response

Builds a `202 Accepted` response; JSON-serializes `value` if given, otherwise an empty body.

acceptstype

accepts: (value: string, expected: string) => boolean

badtype

bad: (detail?: string, init?: ResponseInit) => Response

Alias for {@link badRequest}.

badRequesttype

badRequest: (detail?: string, init?: ResponseInit) => Response

Builds a `400 Bad Request` Problem Details response.

challengetype

challenge: (options?: ChallengeOptions) => Response

Builds a `401`/`407` Problem Details response with a `WWW-Authenticate` (or `Proxy-Authenticate` for `407`) challenge header.

conflicttype

conflict: (detail?: string, init?: ResponseInit) => Response

Builds a `409 Conflict` Problem Details response.

contentTypetype

contentType: (value: string | null) => string | undefined

createdtype

created: (value?: JsonValue, init?: ResponseInit) => Response

Builds a `201 Created` response; JSON-serializes `value` if given, otherwise an empty body.

createEventStreamtype

createEventStream: (options?: EventStreamOptions) => EventStream

Creates a Server-Sent Events stream backed by a `text/event-stream` `Response`, with bounded backpressure-aware writes, optional heartbeat comments, and automatic closing when `options.signal` aborts or `close()` is called.

errortype

error: (status?: number, detail?: string, init?: ResponseInit) => Response

Builds a Problem Details error response with a configurable status (default `500`).

EventStreamtype

EventStream: any

A live Server-Sent Events stream, backed by a streaming `Response`.

response
readonly response: Response;
closed
readonly closed: Promise<void>;
send
Queues an event in order. Await or otherwise handle the returned promise before producing without bound. Rejects with `QuotaExceededError` when the pending-write limit is full.
comment
Queues an SSE comment in order. Rejects with `QuotaExceededError` when the pending-write limit is full.
close
close(): Promise<void>;

EventStreamOptionstype

EventStreamOptions: any

Options for {@link createEventStream}.

signal
Aborting this signal closes the stream.
heartbeatInterval
If set, sends a `heartbeat` comment on this interval (in ms) to keep the connection alive.
highWaterMark
Backpressure threshold for the underlying `ReadableStream` and maximum number of unresolved `send()`/`comment()` calls admitted at once. Defaults to 16.
headers
headers?: HeadersInit;

forbiddentype

forbidden: (detail?: string, init?: ResponseInit) => Response

Builds a `403 Forbidden` Problem Details response.

formatServerSentEventtype

formatServerSentEvent: (event: ServerSentEvent) => string

Serializes a {@link ServerSentEvent} to the `text/event-stream` wire format, escaping multi-line data/comment fields and validating that `event`/`id` contain no line breaks.

internalServerErrortype

internalServerError: (detail?: string, init?: ResponseInit) => Response

Builds a `500 Internal Server Error` Problem Details response.

jsontype

json: (value: JsonValue, init?: ResponseInit) => Response

Builds a `200 OK`-shaped JSON response, serializing `value` and setting the JSON content type.

methodNotAllowedtype

methodNotAllowed: (allow?: string | readonly string[], init?: ResponseInit) => Response

Builds a `405 Method Not Allowed` Problem Details response, setting the `Allow` header if given.

noContenttype

noContent: (init?: ResponseInit) => Response

Builds a `204 No Content` response with an empty body.

notFoundtype

notFound: (detail?: string, init?: ResponseInit) => Response

Builds a `404 Not Found` Problem Details response.

notImplementedtype

notImplemented: (detail?: string, init?: ResponseInit) => Response

Builds a `501 Not Implemented` Problem Details response.

oktype

ok: (value?: JsonValue, init?: ResponseInit) => Response

Builds a `200 OK` response; JSON-serializes `value` if given, otherwise an empty body.

problemtype

problem: (status: number, detail?: string, options?: ProblemOptions & { init?: ResponseInit; }) => Response

Builds an RFC 9457 `application/problem+json` response, defaulting `type` to `about:blank` and `title` to a standard reason phrase for the given `status` (falling back to "HTTP Error").

redirecttype

redirect: (location: string, status?: 301 | 302 | 303 | 307 | 308) => Response

Builds a redirect response with an empty body and a `Location` header. Defaults to `302 Found`.

serverErrortype

serverError: (detail?: string, init?: ResponseInit) => Response

Alias for {@link internalServerError}.

ServerSentEventtype

ServerSentEvent: any

A single Server-Sent Event; `data` is JSON-serialized unless already a string.

data
data?: unknown;
event
event?: string;
id
id?: string;
retry
retry?: number;

serviceUnavailabletype

serviceUnavailable: (detail?: string, init?: ResponseInit) => Response

Builds a `503 Service Unavailable` Problem Details response.

texttype

text: (value: string, init?: ResponseInit) => Response

Builds a plain-text response, setting the `text/plain; charset=utf-8` content type.

tooManyRequeststype

tooManyRequests: (detail?: string, init?: ResponseInit) => Response

Builds a `429 Too Many Requests` Problem Details response.

unauthorizedtype

unauthorized: (detail?: string, init?: ResponseInit) => Response

Builds a `401 Unauthorized` Problem Details response.

unprocessableEntitytype

unprocessableEntity: (detail?: string, init?: ResponseInit) => Response

Builds a `422 Unprocessable Entity` Problem Details response.