axios-mapper can make ts project easy to transform model 🚀🚀 and Prevent duplicate network requests
npm install axios-mapper
or
yarn add axios-mapper
- axios easy to request and return data auto transform model
- prevent duplicate network requests
1、base setting
import HttpClient,{HttpClientConfig} from "../src/index";
const config:HttpClientConfig = {
baseURL:'http://www.httpbin.org',
headers:{
token:'your token'
}
}
const https = new HttpClient(config)
export default https
2 、use tool get model
vscode extension : json2ts web:http://json2ts.com
// {
// "slideshow": {
// "author": "Yours Truly",
// "date": "date of publication",
// "slides": [
// {
// "title": "Wake up to WonderWidgets!",
// "type": "all"
// },
// {
// "items": [
// "Why <em>WonderWidgets</em> are great",
// "Who <em>buys</em> WonderWidgets"
// ],
// "title": "Overview",
// "type": "all"
// }
// ],
// "title": "Sample Slide Show"
// }
// }
export interface Slide {
title: string;
type: string;
}
export interface Slideshow {
author: string;
date: string;
slides: Slide[];
title: string;
}
export interface RootObject {
slideshow: Slideshow;
}
3、request
import https from "./http";
import { RootObject } from "./model";
https.request<RootObject>('/json').then((res)=>{
console.log(res?.slideshow);
})
- axios
- qs
use tsdx to publish
axios-mapper: Axios is open-sourced software licensed under the MIT license.