1.0.7 • Published 3 years ago

grubtech-backend-communication-module v1.0.7

Weekly downloads
-
License
Grubtech
Repository
-
Last release
3 years ago

HTTP Communicator Library

Handles authentication on grub eco system

Installation

npm install @grubtech/http-communicator-module

Usaged

http module configure

import { GrubhttpModule } from "@grubtech/http-communicator-module";

const getAuthToken = () => {
  return Math.floor(Math.random() * 10);
};

export const newInstanceOfhttpModule = new GrubhttpModule({
  jsonplaceholder: "https://jsonplaceholder.typicode.com",
  getAuthToken,
});

now use the 'newInstanceOfhttpModule' as needed

import { newInstanceOfhttpModule } from "../../../some/location";
newInstanceOfhttpModule.post(
  baseURL: "jsonplaceholder",
  targetURL: "/posts/1",
  data: JSON.stringify({ id: 1, title: "foo", body: "bar", userId: 1 })
  retries: 3
);
newInstanceOfhttpModule.get(
  baseURL: "jsonplaceholder",
  targetURL: "/posts/1",
  cache: {
    ttl: 20 // seconds
  },
  retries: 3
);
newInstanceOfhttpModule.patch(
  baseURL: "jsonplaceholder",
  targetURL: "/posts/1",
  data: JSON.stringify({ id: 1, title: "foo", body: "bar", userId: 1 })
  retries: 3
);
newInstanceOfhttpModule.put(
  baseURL: "jsonplaceholder",
  targetURL: "/posts/1",
  data: JSON.stringify({ id: 1, title: "foo", body: "bar", userId: 1 })
  retries: 3
);
newInstanceOfhttpModule.delet(
  baseURL: "jsonplaceholder",
  targetURL: "/posts/1",
  retries: 3
);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Grubtech