Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TinyHttpClient

Tiny HTTP Client Instance.

Here you can create your tiny http instance. Example:

import { TinyHttpClient } from "../index";

const client = new TinyHttpClient({ baseURL: "https://hastebin.com" });
const content = "hello world";

client.post("documents", content).then((response) => {
response.getJSON().then(console.log);
});

Hierarchy

  • TinyHttpClient

Index

Constructors

constructor

Properties

_handle

_handle: (req: ClientRequest, res: IncomingMessage, resolveFunc: (value: OmittedResponse) => void, rejectFunc: (reason?: unknown) => void, isStream?: boolean) => void = ...

Type declaration

    • (req: ClientRequest, res: IncomingMessage, resolveFunc: (value: OmittedResponse) => void, rejectFunc: (reason?: unknown) => void, isStream?: boolean): void
    • Handling response

      Parameters

      • req: ClientRequest

        ClientRequest

      • res: IncomingMessage

        IncomingMessage Response

      • resolveFunc: (value: OmittedResponse) => void

        Resolve function

      • rejectFunc: (reason?: unknown) => void

        Reject function

          • (reason?: unknown): void
          • Parameters

            • Optional reason: unknown

            Returns void

      • isStream: boolean = false

      Returns void

clientOptions

clientOptions: TinyHttpBase

Methods

delete

  • Alias 'get' function, but with 'DELETE' method.

    Parameters

    • url: string

      A valid URL

    • opts: TinyHttpOptions = ...

      Request Options

      Example:

      TinyHttpClient.delete("https://somesite.com/users/40");
      

    Returns Promise<OmittedResponse>

get

  • Here, you could receive response with GET method.

    Parameters

    • url: string

      A valid URL want to request

    • opts: TinyHttpOptions = ...

      Request Options

      Example:

      TinyHttpClient.get("https://hastebin.com", { ... });
      

    Returns Promise<OmittedResponse>

Private handleMessage

  • handleMessage(req: ClientRequest, res: IncomingMessage, resolveFunc: (value: OmittedResponse) => void, rejectFunc: (reason?: unknown) => void, isStream?: boolean): void
  • Handling response

    Parameters

    • req: ClientRequest

      ClientRequest

    • res: IncomingMessage

      IncomingMessage Response

    • resolveFunc: (value: OmittedResponse) => void

      Resolve function

    • rejectFunc: (reason?: unknown) => void

      Reject function

        • (reason?: unknown): void
        • Parameters

          • Optional reason: unknown

          Returns void

    • isStream: boolean = false

    Returns void

options

  • Alias 'get' function, but with 'OPTIONS' method.

    Parameters

    • url: string

      A valid URL

    • opts: TinyHttpOptions = ...

      Request options

      Example:

      TinyHttpClient.options("https://somesite.com", { ... });
      

    Returns Promise<OmittedResponse>

post

  • Well, you could receive response with 'POST' method.

    Parameters

    • url: string

      A valid URL

    • Optional body: string | Record<string, unknown>

      Body or content want to send.

    • opts: TinyHttpOptions = ...

      Request Options

      Do you want send JSON? Sure, you could.

      TinyHttpClient.post("https://somesite.com", { hello: "world" });
      

      Or, just a text?

      TinyHttpClient.post("https://hastebin.com/documents", "hello world");
      

    Returns Promise<OmittedResponse>

put

  • Alias 'post' function, but with 'PUT' method.

    Parameters

    • url: string

      A valid URL

    • Optional body: string | Record<string, unknown>

      Body or content want to send.

    • opts: TinyHttpOptions = ...

      Request options

      Example:

      TinyHttpClient.put("https://somesite.com/users/20", { ... });
      

      Or,

      TinyHttpClient.put("https://somesite.com/users/20/note", "hello world");
      

    Returns Promise<OmittedResponse>

Generated using TypeDoc