A simple rest client , abstraction of axios
const jsonService = RestClient("https://jsonplaceholder.typicode.com");
const options = {};
const jsonService = new RestClient(
"https://jsonplaceholder.typicode.com",
options
);
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);
}
field | default | value |
---|---|---|
mimetype | json | 'xml' or 'json' |
basicAuth | null | {'username': '', 'password': ''} |