Git Product home page Git Product logo

rapper's People

Contributors

alvarto avatar bosn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rapper's Issues

不管是overrideFetch还是createFetch,headers选项设置不起作用

不管是overrideFetch还是createFetch,把headers设置成 application/x-www-form-urlencoded 都不起作用,只有写在fetch的第二个参数中有用,且content-type属性必需是小驼峰contentType才行

以下代码设置后是不起作用的:

export const fetch = createFetch(
  {
    /** 'prefix' 前缀,统一设置 url 前缀,默认是 '' */
    // prefix: 'https://rap2api.taobao.org/app/mock/3402',
    fetchOption: {
      /** 全局配置请求 content-type,默认是 'application/json' */
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },

      credentials: 'same-origin',
    },
  },
  { fetchType: FetchType.AUTO },
);

以下代码设置是可以的:

fetch['POST/api/detail'](
      { uid: 1 },
      {
        contentType: 'application/x-www-form-urlencoded',
      }
)

建议生成的 fetch 对象中, 使用泛型来约束类型, 而不是属性

目前生成的代码大概是这样:

export interface IModels {
  'GET/welcome': {
    Req: {},
    Res: {},
  }
}

export const createFetch() {
  return {
    'GET/welcome': (input) => doFetch('GET', '/welcome', input),
    // ...
  }
}

export const fetch = createFetch()

这样会生成大量的没有意义的 api 实例函数(createFetch 函数内返回的对象在编译成 js 后依旧存在), 建议改成这样:

export interface IModels {
  'GET/welcome': {
    Req: {},
    Res: {},
  }
}

export function fetch<K extends keyof IModels>(key: K, input: IModels[K]['Req']): Promise<IModels[K]['Res']> {
  const pos = key.indexOf('/')
  const method = key.substr(0, pos)
  const url = key.substr(pos)

  return doFetch(method, url, input)
}

这样生成的 js 代码就只有一个 fetch 实例了, 会简单很多, 并且 IDE 在提示的时候, 对函数参数的支持会比 ['GET/welcome'] 这种形式更友好.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.