https://github.com/nixjs/axios-client
A small wrapper for integrating Axios to Typescript
https://github.com/nixjs/axios-client
axio-client axios axios-react axios-wrapper get http-client javascript post typescript
Last synced: 3 months ago
JSON representation
A small wrapper for integrating Axios to Typescript
- Host: GitHub
- URL: https://github.com/nixjs/axios-client
- Owner: nixjs
- Created: 2022-07-02T12:32:51.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-26T15:19:33.000Z (over 2 years ago)
- Last Synced: 2025-01-15T14:23:13.314Z (3 months ago)
- Topics: axio-client, axios, axios-react, axios-wrapper, get, http-client, javascript, post, typescript
- Language: TypeScript
- Homepage:
- Size: 16.6 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @nixjs23n6/axios-client
A small wrapper for integrating Axios to Typescript
## Quick Setup
### Install
Install these dependencies:
`yarn add @nixjs23n6/axios-client`
### Setup & Usage
```javascript
import { HttpClient, Types } from '@nixjs23n6/axios-client'class Client extends HttpClient {
/**
* The Singleton's constructor should always be private to prevent direct
* construction calls with the `new` operator.
*/
private constructor(args: Types.HttpClientArgs) {
super(args)
}/**
* The static method that controls the access to the singleton instance.
*
* This implementation let you subclass the Singleton class while keeping
* just one instance of each subclass around.
*/
public static get instance(): HttpClient {
if (HttpClient._instance) {
return this._instance
}
this._instance = new HttpClient({
baseURL: "https://api.example.nixjs"
})
if (this._instance && this._instance.client) {
// Config interceptors
this._instance.client.interceptors.request.use(
(config) => config,
(error) => {
return Promise.resolve(error)
}
)
this._instance.client.interceptors.response.use(
(response) => {
// Return a successful response back to the calling service
return response
},
(error) => {
const { response } = errorreturn Promise.resolve(response)
}
)
}
return this._instance
}}
const client = Client.instance;
client.fetch('/login', 'POST', { username: "nghinv", password: 'Abc1@34' }).then(console.log)
```