Skip to main content

axios

axios api is a partial implementation of axios, which fetches data from an HTTP server.

caution

The return value of the axios API here is different from the JS axios. The axios API here only returns the data. If you need the headers and other related data, you need to use axiosFull.

Api Parameters

nametyperequireddescription
configAxiosRequestConfigtrueAxios request config

Method Signature

import type { AxiosRequestConfig } from "axios";
// responseData is the data returned by the requested service
export type ResponseData = any;
export declare const axios: (config: AxiosRequestConfig) => Promise<ResponseData>;

export interface AxiosError {
response: {
data: any;
}
}

export interface AxiosFullResponse {
data: ResponseData;
headers: Record<string, any>;
status: number;
statusText: string;
}

export declare const axiosFull: (config: AxiosConfig) => Promise<AxiosFullResponse>

Example

import { axios } from "@giteeteam/apps-api";

export const run = async () => {
try {
const data = await axios({
url,
method: "post",
data: {},
headers: {},
});
} catch(err: AxiosError) {
// You can get the returned data from err.response.data
throw new Error(err.response?.data?.message)
}

try {
const { data, status, headers } = await axiosFull({
url,
method: "post",
data: {},
headers: {},
});
} catch(err: AxiosError) {
// You can get the returned data from err.response.data
throw new Error(err.response?.data?.message)
}
};