@fiswat/network
v1.0.2
Published
A simple tool for handling network calls
Downloads
52
Readme
@fiswat/network
A simple library to handle network calls.
Installation
Install this package using npm:
npm install @fiswat/network
Usage
Network
The Network class provides a way to call and handle APIs via axios without writing additional error handling logics. Require or import it from the package:
// CommonJS (require)
const { Network } = require('@fiswat/network');
// ECMAScript (import)
import { Network } from '@fiswat/network';
Call an API
To call an API, use Network.call()
:
// Axios Request config object
const config = {
method : "get",
url : "baseurl/endurl",
params : {
id: 12
}
}
const response = await Nework.call(config);
console.log(response);
// {data: {...}, status: 200} or {error: {...}, status: 400}