@nelreina/rest-client

2.15.0 • Public • Published

@nelreina/rest-client

A simple rest client , abstraction of axios

Migration from 1

Version 1

const jsonService = RestClient("https://jsonplaceholder.typicode.com");

Version 2 is Class Based

const options = {};
const jsonService = new RestClient(
  "https://jsonplaceholder.typicode.com",
  options
);

Usage / Example

import RestClient from "@nelreina/rest-client";
const jsonService = new RestClient("https://jsonplaceholder.typicode.com");
const xmlService = new RestClient("http://localhost:1234", { mimetype: "xml" });

// Basic Authorization
const basicAuth = { username: "", password: "" };
const authService = new RestClient("http://localhost:1234", { basicAuth });

// Call the api
try {
  // Get route
  const data = await jsonService.get("/todos/1");

  // POST route
  const data2 = await xmlService.post("/test", { message: "post me" });
} catch (error) {
  console.log(error.message);
}

Options

field default value
mimetype json 'xml' or 'json'
basicAuth null {'username': '', 'password': ''}

Readme

Keywords

none

Package Sidebar

Install

npm i @nelreina/rest-client

Weekly Downloads

1

Version

2.15.0

License

ISC

Unpacked Size

12.2 kB

Total Files

13

Last publish

Collaborators

  • nelreina