@fujia/request
v0.3.1
Published
A simple Ajax library build on axios
Downloads
1
Readme
A simple Ajax library build on axios.
English | 简体中文
Installing
Using npm:
npm i @fujia/request
Using yarn:
yarn add axios
Using unpkg CDN:
<script src="https://unpkg.com/@fujia/[email protected]/lib/request.min.js"></script>
Example
Configuring your request as you like:
// ax.ts
import { Request } from '@fujia/request';
import type { RequestConfig } from '@fujia/request';
interface DogRes {
message: string;
status: string;
}
const request = new Request({
timeout: 1000 * 60 * 5,
interceptors: {
requestInterceptors: (config) => {
console.log('interceptor of instance request');
return config;
},
responseInterceptors: (res) => {
console.log('interceptor of instance request');
return res;
},
},
});
export const fjRequest = (config: RequestConfig) => {
return request.request<DogRes>(config);
};
Using the instance as following:
// dogs.ts
import { fjRequest } from './ax';
function main() {
fjRequest({
url: 'https://dog.ceo/api/breeds/image/random',
}).then((res) => {
if (res.status === 'success') {
console.log(res.message);
}
});
}
main();