UNPKG

sync-request-curl

Version:

Fast way to send synchronous web requests in NodeJS. API is a subset of sync-request. Leverages node-libcurl for high performance. Cannot be used in a browser.

48 lines (47 loc) 1.81 kB
import { CurlOption, Easy, HttpPostField, HttpPostField as HttpPostField$1 } from "node-libcurl"; import { IncomingHttpHeaders } from "http"; //#region src/types.d.ts type HttpVerb = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'; type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex'; type SetEasyOptionCallback = (curl: Easy, curlOption: CurlOption) => void; interface Options { headers?: IncomingHttpHeaders; qs?: { [key: string]: any; }; json?: any; body?: string | Buffer; formData?: HttpPostField$1[]; timeout?: number; followRedirects?: boolean; maxRedirects?: number; insecure?: boolean; setEasyOptions?: SetEasyOptionCallback; } type GetBody = { <Encoding extends BufferEncoding>(encoding: Encoding): string; (encoding?: undefined): Buffer; }; type GetJSON = <T = any>(encoding?: BufferEncoding) => T; interface Response { statusCode: number; headers: IncomingHttpHeaders; url: string; body: string | Buffer; getBody: GetBody; getJSON: GetJSON; } //#endregion //#region src/request.d.ts /** * Performs an HTTP request using cURL with the specified parameters. * * @param {HttpVerb} method - The HTTP method for the request (e.g., 'GET', 'POST') * @param {string} url - The URL to make the request to * @param {Options} [options={}] - An object to configure the request * @returns {Response} - HTTP response consisting of status code, headers, and body */ declare const request: (method: HttpVerb, url: string, options?: Options) => Response; //#endregion export { type BufferEncoding, type HttpPostField, type HttpVerb, type Options, type Response, type SetEasyOptionCallback, request as default }; //# sourceMappingURL=index.d.mts.map