0.0.1 • Published 5 years ago

@elijahjcobb/request v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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.