@mljsdev/rest-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

REST CLIENT

This package is a helper to easily make an HTTP REST request. it's based on Axios and it response schema is the same as Axios Response Schema

Installation

Use this command to install the package

  npm install @mljsdev/rest-client

Usage/Examples

First, import the RestClient, then define your default client configuration. For more details on configuration refer to AxiosRequestConfig

import { RestClient } from '@mljsdev/rest-client'

const config = {
    baseURL: "https://yawa.sedana.io",
    headers: {
        Authorization: `Bearer ${process.env.AUTH_TOKEN}`,
    },
};

Then, create a new instance of the RestClient with your configuration

const client = new RestClient(config);

Now you can perform requests like GET, POST, PUT, DELETE and even PATCH

  • GET example
const client = new RestClient(config);
const instance = await client.get('/api/instances').then(res => res.data);

console.log(instance);

Response be like:

{
    "id": 1,
    "name": "first instance",
    "instanceID": "instance1",
    "token": "hbdfbudifujr",
    "active": true,
    "status": "WORKING",
    "note": null,
    "userId": "c652e8a3-3683-41a3-8eda-146aa9d79poi",
    "expiredAt": "2024-02-11T00:00:00.000Z",
    "createdAt": "2023-08-11T15:14:26.000Z",
    "updatedAt": "2023-11-04T16:21:09.000Z",
    "deletedAt": null
}
  • POST example
const client = new RestClient(config);
const instance = await client.post(
    '/api/instances', 
    { 
        name: "second instance" 
    }
).then(res => res.data);
  • PUT example
const client = new RestClient(config);
const instance = await client.put(
    '/api/instances/1', 
    { 
        name: "update second instance" 
    }
).then(res => res.data);

Support

For support, email marcuslogane@eka-digital.com

Authors

Package Sidebar

Install

npm i @mljsdev/rest-client

Weekly Downloads

1

Version

1.0.8

License

ISC

Unpacked Size

27.2 kB

Total Files

25

Last publish

Collaborators

  • marcusholloway17