@fujia/fetch
v0.7.2
Published
A simple http request library build on fetch
Downloads
1
Readme
A simple http request library build on fetch.
English | 简体中文
Installing
Using npm:
npm install @fujia/fetch
Using yarn:
yarn add @fujia/fetch
Using unpkg CDN:
<script src="https://unpkg.com/@fujia/fetch/lib/request.min.js" />
Usage
A simple example as follows:
import { Request } from '@fujia/fetch';
type User = {
id: string;
name: string;
avatar?: string;
};
interface UserData {
success: boolean;
data?: User;
}
const request = Request.create({
baseUrl: 'http://localhost:3001',
requestInterceptor: (config) => {
config.headers['authorization'] = `Bearer token`;
return config;
},
});
export const asyncFetchUserInfo = async () => {
const res = await request<UserData>('/user'});
if (res.success) {
console.log(res.data);
}
};