当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript axios.create函数代码示例

本文整理汇总了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;
开发者ID:vvscode,项目名称:code-notes,代码行数:7,代码来源:client.ts

示例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,
开发者ID:taimur38,项目名称:toombot,代码行数:31,代码来源:tank-hunter.ts

示例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
开发者ID:SteveTannnnng,项目名称:Mob,代码行数:31,代码来源:request.ts

示例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,
})
开发者ID:whitetrefoil,项目名称:flickr-simple-reorder,代码行数:16,代码来源:base.ts

示例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);
    };
开发者ID:vanilla,项目名称:vanilla,代码行数:32,代码来源:apiv2.ts

示例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)
};
开发者ID:JimmyLv,项目名称:blog,代码行数:19,代码来源:index.ts

示例7: constructor

 constructor(subscriptionKey: string, apiUrl: string) {
   this.axiosInstance = axios.create({
     baseURL: apiUrl,
     headers: { "Ocp-Apim-Subscription-Key": subscriptionKey },
   });
 }
开发者ID:baohouse,项目名称:baohouse.github.io,代码行数:6,代码来源:FaceCognitionService.ts

示例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"
开发者ID:endway,项目名称:songSearchBot,代码行数:32,代码来源:spotify.ts

示例9:

import axios from 'axios'
import {baseURL} from '@/config'

let axiosCopy = axios.create({
    baseURL
})

export default axiosCopy
开发者ID:GeSnowBoy,项目名称:pachong,代码行数:8,代码来源:index.ts

示例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',
});
开发者ID:wKovacs64,项目名称:hibp,代码行数:11,代码来源:axiosInstance.ts


注:本文中的axios.create函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。