rest-api-client-framework
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

About

Rest client framework for your api client. In below example how to use this simple script

Write quick your api client

Example

// Client Stratgy
import { ClientInterface, Request, Response, ConfigType, ResponseInterface } from "@gawsoft/rest-api-client-framework";

export class ClientTest implements ClientInterface {
  private api_key: string;

  constructor(api_key: string) {
    this.setApiKey(api_key);
  }

  setApiKey(api_key: string) {
    this.api_key = api_key;
  }

  config(): ConfigType {
    return {
      endpoint: "https://httpbin.org",
      timeout: 10000,
    };
  }

  globalHeaders(): Record<string, string> {
    return {};
  }

  setAuthentication(request: Request): void {
    request.addHeaders({ authorization: `Bearer ${this.api_key}` });
  }
  
  // Controllers
    async extract(url: string): Promise<ResponseInterface> {
        const request = new Request(this);

        request.addHeaders({
            "Accept-Encoding": "gzip",
            "Content-Type": "application/json",
        });

        const response = await request.post(`/person`, { name: "Johnny Kowalski" });
        if (response.status !== 200)
            throw new Error(
                `Cant download json file from server status code: ${response.status}`
            );

        return new Response(response);
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i rest-api-client-framework

Homepage

gawsoft.com

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

81.7 kB

Total Files

94

Last publish

Collaborators

  • gawsoft