/** * Module for unified HTTP request/response handling. * * This module defines the common building blocks for HTTP requests and * responses. * * @packageDocumentation */ import { HttpResponse } from "./response.js"; import { TO_HTTP_RESPONSE, type ToHttpResponse } from "./to-response.js"; /** * An empty response with 204 No Content status. */ export declare const noContentResponse: ToHttpResponse; /** * Represents a type that can be serialized into JSON format. * * This type encompasses common JSON-compatible values including strings, * numbers, booleans, null, arrays of JSON-serializable values, and objects * with JSON-serializable properties. * * Additionally, it includes objects that implement a `toJSON` method to define * their custom serialization logic. */ export type JsonSerializable = string | number | boolean | null | JsonSerializable[] | { [key: string]: JsonSerializable | undefined; } | { toJSON: () => JsonSerializable; }; /** * A JSON response with the content-type header set to application/json. */ export declare const jsonResponse: (value: JsonSerializable) => ToHttpResponse; /** * An HTML response with the content-type header set to text/html. */ export declare const htmlResponse: (html: string, charset?: string) => ToHttpResponse; /** * Response that redirects the request to another location. * * @example * ```ts * import { Redirect } from "@taxum/core/http"; * import { m, Router } from "@taxum/core/routing"; * * const router = new Router() * .route("/old", m.get(() => Redirect.permanent("/new"))) * .route("/new", m.get(() => "Hello!")); * ``` */ export declare class Redirect implements ToHttpResponse { private readonly statusCode; private readonly uri; private constructor(); /** * Create a new {@link Redirect} that uses `303 See Other` status code. * * This redirect instructs the client to change the method to GET for the * subsequent request to the given `uri`, which is useful after successful * form submission, file upload or when you generally don't want the * redirected-to page to observe the original request method and body * (if non-empty). If you want to preserve the request method and body, * {@link Redirect.temporary} should be used instead. * * See [MDN: 303 See Other](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303) */ static to(uri: URL | string): Redirect; /** * Create a new {@link Redirect} that uses `307 Temporary Redirect` status * code. * * This has the same behavior as {@link Redirect.to}, except it will * preserve the original HTTP method and body. * * See [MDN: 307 Temporary Redirect](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307) */ static temporary(uri: URL | string): Redirect; /** * Create a new {@link Redirect} that uses `308 Permanent Redirect` status * code. * * See [MDN: 308 Permanent Redirect](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308) */ static permanent(uri: URL | string): Redirect; [TO_HTTP_RESPONSE](): HttpResponse; }