Socket
Socket
Sign inDemoInstall

rest-api-client-framework

Package Overview
Dependencies
9
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rest-api-client-framework

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


Version published
Maintainers
1
Install size
2.19 MB
Created

Readme

Source

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);
    }
}



FAQs

Last updated on 20 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc