# @askrjs/server/http

> Published API exports for @askrjs/server/http.

Source: [https://askrjs.com/docs/reference/api/server/http](https://askrjs.com/docs/reference/api/server/http)

Status: stable. Packages: @askrjs/server/http.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Exports

This entrypoint publishes 33 exports from the declarations shipped by @askrjs/server.

### `accepted`

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

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

### `accepts`

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

### `bad`

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

Alias for {@link badRequest}.

### `badRequest`

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

Builds a `400 Bad Request` Problem Details response.

### `challenge`

```ts
challenge: (options?: ChallengeOptions) => Response
```

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

### `clearCookie`

```ts
clearCookie: (response: Response, name: string, options?: CookieOptions) => Response
```

Returns a clone of `response` with a `Set-Cookie` header that expires and clears `name`.

### `conflict`

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

Builds a `409 Conflict` Problem Details response.

### `contentType`

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

### `created`

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

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

### `createEventStream`

```ts
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.

### `error`

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

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

### `EventStream`

```ts
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>;

### `EventStreamOptions`

```ts
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;

### `explicitlyAccepts`

```ts
explicitlyAccepts: (value: string, expected: string) => boolean
```

### `forbidden`

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

Builds a `403 Forbidden` Problem Details response.

### `formatServerSentEvent`

```ts
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.

### `internalServerError`

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

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

### `json`

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

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

### `methodNotAllowed`

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

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

### `noContent`

```ts
noContent: (init?: ResponseInit) => Response
```

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

### `notFound`

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

Builds a `404 Not Found` Problem Details response.

### `notImplemented`

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

Builds a `501 Not Implemented` Problem Details response.

### `ok`

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

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

### `problem`

```ts
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").

### `redirect`

```ts
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`.

### `serverError`

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

Alias for {@link internalServerError}.

### `ServerSentEvent`

```ts
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;

### `serviceUnavailable`

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

Builds a `503 Service Unavailable` Problem Details response.

### `setCookie`

```ts
setCookie: (response: Response, name: string, value: string, options?: CookieOptions) => Response
```

Returns a clone of `response` with an additional `Set-Cookie` header appended, serialized
from `name`, `value`, and `options`.

### `text`

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

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

### `tooManyRequests`

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

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

### `unauthorized`

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

Builds a `401 Unauthorized` Problem Details response.

### `unprocessableEntity`

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

Builds a `422 Unprocessable Entity` Problem Details response.

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/server/router/index.md) | [Next](https://askrjs.com/docs/reference/api/server/middleware/index.md)
