0.0.1 • Published 2 years ago
@portalx/request v0.0.1
@portalx/request
准备
安装 @fishx/i18n@1.0.7
和 antd@4.24.8
使用
和 axios
一致
GET
import { request } from '@portalx/request';
export async function getAllUser() {
return request('/users');
}
export async function getUser(userId: number) {
return request(`/user/${userId}`);
}
POST
export async function editUser(userId: number, params: any) {
return request(`/user/${userId}`, {
method: 'POST',
data: params,
// 设置headers
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
});
}
PATCH
export async function changeUserInfo(params: any) {
return request('/users/info', {
method: 'PATCH',
data: params,
});
}
DELETE
export async function deleteUser(userId: number) {
return request(`/user/${userId}`, {
method: 'DELETE',
});
interface
// 预期的通用返回结构体
export interface ICommonRes<T = any> {
success: boolean;
data: T;
stack?: string;
message?: string;
code?: string;
resultCode?: string;
resultObject?: object;
resultMsg?: string;
}
// 通用失败返回体
export interface IErrorRes {
code?: string;
message?: string;
[props: string]: any;
}
其他
设置登录重定向路由前缀 window.portalxWebRoot
默认 /portal
设置请求前缀 window.portalxRequestPrefix
默认 /portal/api
0.0.1
2 years ago
0.0.1-canary.20230629.3
2 years ago
0.0.1-canary.20230629.2
2 years ago
0.0.1-canary.20230629.1
2 years ago
0.0.1-canary.20230620.1
2 years ago