0.1.1 • Published 2 years ago
@umijs/request2type v0.1.1
request2type
a tool for generating type of request params/payload/query, works in http-proxy-middleware.
Install
$ yarn add @umijs/request2type --dev
Usage
In Umi
- add handler in umi config file.
import { EventHandler } from '@umijs/request2type';
export default {
proxy: {
'/api': {
target: 'http://localhost:8080',
onProxyReq: EventHandler.onProxyReq(proxyReq, req, res),
onProxyRes: EventHandler.onProxyRes(proxyRes, req, res),
},
},
};
- add type file to tsconfig.json
{
"typeRoots": ["./types"]
}
- start with node env
$ REQUEST_LISTEN=1 umi dev
- use type in request, all types export from namespace
API
const getUserInfo = (query: API.GET_API_USER_INFO_QUERY) => {
return axios.get<typeof query, AxiosResponse<API.GET_API_USER_INFO_RES>>(
`/api/userInfo?${stringify(query)}`
);
};