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

0.5.0 • Public • Published

@thaitype/rest-client

Lightweight REST client helper function wrapping with type and Axios

CI

Introduction

Lightweight REST client helper function with basic type support and Axios wrapper. However, if you need more type-safety, we recommend considering untypeable.

Alternatively, if you have control over both the server and client types, options like tRPC or GraphQL are great choices. So go ahead and choose the option that works best for your needs!

Installation

npm i @thaitype/rest-client

Examples

import { RestClient } from '@thaitype/rest-client';

async function main() {
  const client = new RestClient();
  const res = await client.request('GET https://jsonplaceholder.typicode.com/posts/{postId}/comments', {
    params: {
      postId: 1,
    },
  });
  console.log(res.data);
}

main();

Use with Axios Retry

import { RestClient } from '@thaitype/rest-client';
import axios from 'axios';
import axiosRetry from 'axios-retry';

// Create an an axios instance and apply axiosRetry
const axiosInstance = axios.create();
axiosRetry(axiosInstance, { retries: 3 });

// Using axiosInstance in RestClient
const client = new RestClient({
  axiosInstance,
});
// This will retry 3 times
await client.request('GET http://domain.com');

API

to be add later

Readme

Keywords

none

Package Sidebar

Install

npm i @thaitype/rest-client

Weekly Downloads

1

Version

0.5.0

License

MIT

Unpacked Size

39.8 kB

Total Files

14

Last publish

Collaborators

  • mildronize