本文整理汇总了TypeScript中axios.create函数的典型用法代码示例。如果您正苦于以下问题:TypeScript create函数的具体用法?TypeScript create怎么用?TypeScript create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
import axios from "axios";
const client = axios.create({
baseURL: "https://jsonplaceholder.typicode.com"
});
export default client;
示例2: onMessage
import * as axios from 'axios';
import { bot } from '../constants'
import * as context from './context'
const session = axios.create({
baseURL: process.env.TANK_URL,
headers: {}
})
function* onMessage(message : SlackMessage ) : Iterator<Promise<MinionResult>> {
const response = yield Promise.resolve({
send: true,
text: 'hi',
threadReply: true,
filter: (msg : SlackMessage) => msg.text.search(/apartment/gi) > -1,
contextMatch: (msg : SlackMessage) => msg.user.id == message.user.id && msg.channel.id == message.channel.id,
requirements: []
});
let all_apts = [];
yield session.get(`/parseit`)
.then(rsp => rsp.data)
.then(function (results : any) : MinionResult {
all_apts = results.allMsgs;
return {
send: true,
text: 'found your apartments!',
threadReply: true,
filter: (msg : SlackMessage) => msg.text.search(/see/gi) > -1,
示例3:
import Axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import { notification } from 'antd';
import hash from 'hash.js';
import router from 'umi/router';
import genXmSign from './xmSign';
const DEFAULT_EXPIRY = 3600; // sec
const BASE_URL = 'https://www.ximalaya.com/revision/';
const instance: AxiosInstance = Axios.create({
baseURL: BASE_URL,
timeout: 3000,
// withCredentials: true, // todo change
});
// keep only one notification
const createNotification = (message, onClick = undefined) => {
try {
notification.destroy();
} finally {
notification.error({
message,
onClick,
});
}
};
const errorHandler = (error) => {
const { message, status } = error;
// fix for window 403 error
示例4:
// tslint:disable:no-console
import Axios from 'axios'
export interface IResponse<T> {
code: number
devMessage?: object
data: T
}
export const axios = Axios.create({
baseURL: '/api/',
timeout: 10000,
})
示例5: fieldErrorTransformer
import { humanFileSize } from "@library/utility/fileUtils";
import { IApiError, IFieldError } from "@library/@types/api/core";
function fieldErrorTransformer(responseData) {
if (responseData && responseData.status >= 400 && responseData.errors && responseData.errors.length > 0) {
responseData.errors = indexArrayByKey(responseData.errors, "field");
}
return responseData;
}
const apiv2 = axios.create({
baseURL: formatUrl("/api/v2/"),
headers: {
common: {
"X-Requested-With": "vanilla",
},
},
transformResponse: [...(axios.defaults.transformResponse as any), fieldErrorTransformer],
paramsSerializer: params => qs.stringify(params),
});
export default apiv2;
export type ProgressHandler = (progressEvent: any) => void;
export function createTrackableRequest(
requestFunction: (progressHandler: ProgressHandler) => () => Promise<AxiosResponse>,
) {
return (onUploadProgress: ProgressHandler) => {
return requestFunction(onUploadProgress);
};
示例6:
import axios from 'axios'
import {Article, ArticleMeta, SignedFileUrls, UnsignedUrl} from "./types";
const client = axios.create();
export const getArticleMetaList = (): Promise<ArticleMeta[]> => {
return client.get(`/api/blog`)
.then(it => it.data)
};
export const getArticle = (id: string): Promise<Article> => {
return client.get(`/api/blog/${id}`)
.then(it => it.data)
};
export const getSignedFileUrls = (urls: UnsignedUrl[]): Promise<SignedFileUrls> => {
return client.post(`/api/notion/getSignedFileUrls`, {urls: urls})
.then(it => it.data)
};
示例7: constructor
constructor(subscriptionKey: string, apiUrl: string) {
this.axiosInstance = axios.create({
baseURL: apiUrl,
headers: { "Ocp-Apim-Subscription-Key": subscriptionKey },
});
}
示例8: createProviderResponder
album: {
images: Array<{ url: string }>
}
}>,
total: number
};
}
interface SpotifyAuthResponse {
"access_token": string;
"token_type": string;
"expires_in": number;
}
const spotifyAccountApi = Axios.create({
baseURL: "https://accounts.spotify.com/api",
});
const spotifyApi = Axios.create({
baseURL: "https://api.spotify.com/v1",
});
const makeResponse = createProviderResponder("Spotify");
async function autenthicate(): Promise<boolean> {
// <base64 encoded client_id:client_secret>
const keys = `${config.get("spotify.clientId")}:${config.get("spotify.clientSecret")}`;
const encodedKeys = base64.encode(utf8.encode(keys));
const requestParams = querystring.stringify({
grant_type: "client_credentials"
示例9:
import axios from 'axios'
import {baseURL} from '@/config'
let axiosCopy = axios.create({
baseURL
})
export default axiosCopy
示例10:
import Axios from 'axios';
/**
* An Axios instance used for API queries. Not meant for general use.
*
* @internal
* @private
*/
export default Axios.create({
baseURL: 'https://api.pwnedpasswords.com',
});