.ts
TypeScript
(application/typescript)
declare module "./http_client" {
  import { IncomingMessage } from "http";

  export class HttpResponse {
    readonly statusCode: number;
    readonly statusText: string;
    readonly ok: boolean;
    readonly headers: IncomingMessage["headers"];

    constructor(incoming: IncomingMessage);

    text(): Promise<string>;
    isJson(): Promise<boolean>;
    json(): Promise<any>;
  }

  export interface RequestConfig {
    headers?: Record<string, string>;
    body?: string | Buffer | any;
  }

  export class HttpClient {
    constructor();

    get(url: string, config?: RequestConfig): Promise<HttpResponse>;
    post(url: string, config?: RequestConfig): Promise<HttpResponse>;
    put(url: string, config?: RequestConfig): Promise<HttpResponse>;
    patch(url: string, config?: RequestConfig): Promise<HttpResponse>;
    delete(url: string, config?: RequestConfig): Promise<HttpResponse>;
    head(url: string, config?: RequestConfig): Promise<HttpResponse>;
    options(url: string, config?: RequestConfig): Promise<HttpResponse>;
    custom(
      method: string,
      url: string,
      config?: RequestConfig,
    ): Promise<HttpResponse>;
  }
}