@elijahjcobb/request
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Request

A package to send and receive data using promises.

Import

import { ECRRequest, ECRResponse, ECRMethod } from "@elijahjcobb/request";

Examples

Promises

let req: ECRRequest = new ECRRequest();

req.setUrl("the-url");
req.setMethod(ECRMethod.Post);
req.setBody({ foo: "hello", bar: "world" });

let res: ECRResponse = req.request();

Callbacks

let req: ECRRequest = new ECRRequest();

req.setUrl("the-url");
req.setMethod(ECRMethod.Post);
req.setBody({ foo: "hello", bar: "world" });

req.requestAsync(((error: Error, response: ECRResponse): void => {}));

Documentation

Everything is completely documented. You can view the declaration files or even the source code on GitHub.

ECRRequest

{
    body: Buffer;
    url: string;
    method: Method;
    headers: object;
    constructor();
    setBearerToken(token: string): void;
    setUrl(url: string): void;
    setMethod(method: Method): void;
    setBody(body: string | object | Buffer): void;
    requestAsync(completion: (error: Error, response: Response) => void): void;
    request(): Promise<Response>;
}

ECRResponse

{
    statusCode: number;
    roundTripTime: number;
    body: string | object | Buffer;
    constructor(response: RequestLib.Response, startTimestamp: number);
    getJSON(): object;
    getBuffer(): Buffer;
    getString(): string;
    getRaw(): string | object | Buffer;
    print(): void;
}

ECRMethod

{
    Get = "GET",
    Post = "POST",
    Put = "PUT",
    Delete = "DELETE"
}

Bugs

If you find any bugs please create an issue on GitHub or if you are old fashioned email me at elijah@elijahcobb.com.

Package Sidebar

Install

npm i @elijahjcobb/request

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

18.7 kB

Total Files

10

Last publish

Collaborators

  • ejc