Skip to content

🚀🚀make ts project easy to requset transform model

License

Notifications You must be signed in to change notification settings

RainManGO/axios-mapper

Repository files navigation

Language: English | 中文简体

axios mapper

npm npm npm npm License

axios-mapper can make ts project easy to transform model 🚀🚀 and Prevent duplicate network requests

Install

  npm install  axios-mapper

or

  yarn add axios-mapper

Features

  • axios easy to request and return data auto transform model
  • prevent duplicate network requests

Usage

  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);
})

Dependency

  • axios
  • qs

Scripts

use tsdx to publish

License

axios-mapper: Axios is open-sourced software licensed under the MIT license.