@anot/http-response-builder
Version:
A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.
118 lines (117 loc) • 4.57 kB
TypeScript
export declare class Paging {
private page?;
private size?;
private total?;
constructor(page?: number, size?: number, total?: number);
setPage(page?: number): this;
setSize(size?: number): this;
setTotal(total?: number): this;
getPage(): number | undefined;
getSize(): number | undefined;
getTotal(): number | undefined;
}
export declare class HttpResponseBuilder<T> {
private status?;
private message?;
private data?;
private paging?;
private metadata?;
constructor(status?: number, message?: string);
static customResponse<T = never>(): HttpResponseBuilder<T>;
static continue<T = never>(): HttpResponseBuilder<T>;
static switchingProtocols<T = never>(): HttpResponseBuilder<T>;
static processing<T = never>(): HttpResponseBuilder<T>;
static ok<T = never>(): HttpResponseBuilder<T>;
static created<T = never>(): HttpResponseBuilder<T>;
static accepted<T = never>(): HttpResponseBuilder<T>;
static nonAuthoritativeInformation<T = never>(): HttpResponseBuilder<T>;
static noContent<T = never>(): HttpResponseBuilder<T>;
static resetContent<T = never>(): HttpResponseBuilder<T>;
static partialContent<T = never>(): HttpResponseBuilder<T>;
static multipleChoices<T = never>(): HttpResponseBuilder<T>;
static movedPermanently<T = never>(): HttpResponseBuilder<T>;
static found<T = never>(): HttpResponseBuilder<T>;
static seeOther<T = never>(): HttpResponseBuilder<T>;
static notModified<T = never>(): HttpResponseBuilder<T>;
static temporaryRedirect<T = never>(): HttpResponseBuilder<T>;
static permanentRedirect<T = never>(): HttpResponseBuilder<T>;
static badRequest<T = never>(): HttpResponseBuilder<T>;
static unauthorized<T = never>(): HttpResponseBuilder<T>;
static paymentRequired<T = never>(): HttpResponseBuilder<T>;
static forbidden<T = never>(): HttpResponseBuilder<T>;
static notFound<T = never>(): HttpResponseBuilder<T>;
static internalServerError<T = never>(): HttpResponseBuilder<T>;
static notImplemented<T = never>(): HttpResponseBuilder<T>;
static badGateway<T = never>(): HttpResponseBuilder<T>;
static serviceUnavailable<T = never>(): HttpResponseBuilder<T>;
static gatewayTimeout<T = never>(): HttpResponseBuilder<T>;
setData(data: T): this;
setMessage(msg: string | undefined): this;
setStatus(status: number | undefined): this;
setPaging(paging: Paging): this;
setMetadata(metadata: Record<string, any>): this;
getMetadata(): any | undefined;
getStatus(): number | undefined;
getMessage(): string | undefined;
getData(): T | undefined;
getPaging(): Paging | undefined;
}
export declare enum HttpStatusCode {
CONTINUE = 100,
SWITCHING_PROTOCOLS = 101,
PROCESSING = 102,
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
MULTIPLE_CHOICES = 300,
MOVED_PERMANENTLY = 301,
FOUND = 302,
SEE_OTHER = 303,
NOT_MODIFIED = 304,
TEMPORARY_REDIRECT = 307,
PERMANENT_REDIRECT = 308,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
PAYMENT_REQUIRED = 402,
FORBIDDEN = 403,
NOT_FOUND = 404,
INTERNAL_SERVER_ERROR = 500,
NOT_IMPLEMENTED = 501,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504
}
export declare enum HttpStatusMessage {
CONTINUE = "Continue",
SWITCHING_PROTOCOLS = "Switching Protocols",
PROCESSING = "Processing",
OK = "OK",
CREATED = "Created",
ACCEPTED = "Accepted",
NON_AUTHORITATIVE_INFORMATION = "Non-Authoritative Information",
NO_CONTENT = "No Content",
RESET_CONTENT = "Reset Content",
PARTIAL_CONTENT = "Partial Content",
MULTIPLE_CHOICES = "Multiple Choices",
MOVED_PERMANENTLY = "Moved Permanently",
FOUND = "Found",
SEE_OTHER = "See Other",
NOT_MODIFIED = "Not Modified",
TEMPORARY_REDIRECT = "Temporary Redirect",
PERMANENT_REDIRECT = "Permanent Redirect",
BAD_REQUEST = "Bad Request",
UNAUTHORIZED = "Unauthorized",
PAYMENT_REQUIRED = "Payment Required",
FORBIDDEN = "Forbidden",
NOT_FOUND = "Not Found",
INTERNAL_SERVER_ERROR = "Internal Server Error",
NOT_IMPLEMENTED = "Not Implemented",
BAD_GATEWAY = "Bad Gateway",
SERVICE_UNAVAILABLE = "Service Unavailable",
GATEWAY_TIMEOUT = "Gateway Timeout"
}
export declare function getHttpStatusMessage(code: HttpStatusCode): HttpStatusMessage | undefined;