UNPKG

@darlean/webservices

Version:

Library for building actor-based webservices via the Darlean Web Gateways service

58 lines (57 loc) 2.63 kB
/// <reference types="node" /> import { IWebGatewayRequest, IWebGatewayResponse } from '@darlean/base'; export type SearchParamSource = 'url' | 'url-when-get' | 'body' | 'body-when-urlencoded'; export declare class WebRequest { protected request: IWebGatewayRequest; private constructor(); static from(request: IWebGatewayRequest): WebRequest; getHeader(header: string): string | undefined; getCookie(name: string): string | undefined; getCookies(name: string): string[]; /** * @returns Whether the request has the provided content type. Matching is performed case-insensitive. */ hasContentType(contentType: string): boolean; /** * @returns The first part of the content type (before the optional semicolon) converted to lowercase. */ getContentType(): string | undefined; /** * @returns The rawe request body as a buffer, or undefined when there is no body. */ getRawBody(): Buffer | undefined; /** * @returns The request body converted to text assuming utf8 encoding, or undefined when there is no body. */ getTextBody(): string | undefined; /** * Get the search parameters from the content body and/or the url as specified by the * ordered list of sources. The parameter values are decoded before they are returned. * Provide either `url` or `url-when-get` (but not both) as source to prevent duplicate results. * Provide either 'body` or `cody-when-urlencoded` (but not both) as source to prevent duplicate results. */ getSearchParams(sources?: SearchParamSource[]): { [key: string]: string[]; }; getUnderlyingRequest(): IWebGatewayRequest; response(): WebResponse; /** * Returns the url-decoded path elements that remain after having been prefix-matched by the web gateway. */ getRemainingPathElements(): string[]; } export declare class WebResponse { protected request: IWebGatewayRequest; protected response: IWebGatewayResponse; protected headersSent: boolean; protected bodyParts: Buffer[]; private constructor(); static from(request: IWebGatewayRequest): WebResponse; endWithStatusCode(statusCode: number, statusMessage: string): Promise<IWebGatewayResponse>; setStatusCode(statusCode: number, statusMessage: string): void; setHeader(header: string, value: string): void; setCookie(value: string): void; push(buffer: Buffer): Promise<void>; pushText(contentType: string, value: string): Promise<void>; end(): Promise<IWebGatewayResponse>; }