项目作者: RainManGO

项目描述 :
🚀🚀make ts project easy to requset transform model
高级语言: TypeScript
项目地址: git://github.com/RainManGO/axios-mapper.git
创建时间: 2020-12-12T08:36:28Z
项目社区:https://github.com/RainManGO/axios-mapper

开源协议:MIT License

下载


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

  1. npm install axios-mapper

or

  1. yarn add axios-mapper

Features

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

Usage

1、base setting

  1. import HttpClient,{HttpClientConfig} from "../src/index";
  2. const config:HttpClientConfig = {
  3. baseURL:'http://www.httpbin.org',
  4. headers:{
  5. token:'your token'
  6. }
  7. }
  8. const https = new HttpClient(config)
  9. export default https

2 、use tool get model

vscode extension : json2ts
web:http://json2ts.com

  1. // {
  2. // "slideshow": {
  3. // "author": "Yours Truly",
  4. // "date": "date of publication",
  5. // "slides": [
  6. // {
  7. // "title": "Wake up to WonderWidgets!",
  8. // "type": "all"
  9. // },
  10. // {
  11. // "items": [
  12. // "Why <em>WonderWidgets</em> are great",
  13. // "Who <em>buys</em> WonderWidgets"
  14. // ],
  15. // "title": "Overview",
  16. // "type": "all"
  17. // }
  18. // ],
  19. // "title": "Sample Slide Show"
  20. // }
  21. // }
  22. export interface Slide {
  23. title: string;
  24. type: string;
  25. }
  26. export interface Slideshow {
  27. author: string;
  28. date: string;
  29. slides: Slide[];
  30. title: string;
  31. }
  32. export interface RootObject {
  33. slideshow: Slideshow;
  34. }

3、request

  1. import https from "./http";
  2. import { RootObject } from "./model";
  3. https.request<RootObject>('/json').then((res)=>{
  4. console.log(res?.slideshow);
  5. })

Dependency

  • axios
  • qs

Scripts

use tsdx to publish

License

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