UNPKG

portals

Version:

Client-side HTTP requests with middleware support.

19 lines (18 loc) 881 B
import { Request, Response, Middleware, HttpHeaderLiteral } from "./"; export declare type Portal<Request, Response> = (request: Request) => Promise<Response>; /** * Read all response headers from the given XHR instance into a standard * object literal. */ export declare function getAllHeaders(xhr: XMLHttpRequest): HttpHeaderLiteral; /** * Sends the request to the server. This is used by createPortal() after * all middleware has been applied. */ export declare function send(request: Request): Promise<Response>; /** * Creates and returns a new "portal" instance for creating HTTP * requests. Each request and response is passed through the * given middleware. */ export declare function createPortal(...middleware: Middleware[]): <Req extends Request<any> = Request<any>, Res extends Response<any> = Response<any>>(request: Req) => Promise<Res>;