Home > @dinofe/xt-core > createHttp

# createHttp() function

根据配置创建 HTTP 实例

Signature:

export declare function createHttp(config: HttpConfig): XApisauceInstance;

# Parameters

Parameter Type Description
config HttpConfig 配置项

Returns:

XApisauceInstance

返回 HTTP 实例

# Example

简单示例一:

import { createHttp } from '@dinofe/xt-core/http'
const http = createHttp({
 baseURL: '/api-abc',
 useEncrypt: true,
 useSign: true,
 appKey: '3a2e424c56754e90a8948b74f163f0cb',
 encryptVersion: '2',
 commonParams: () => ({
   appId: '3130042001040',
   deviceId: 'xxx_h5',
   merNoNo: '130042001040'
 }),
 onFail: (msg) => {
   log(msg)
 },
 onInvalidToken: (res) => {
   log('Token已失效', res.code, res.msg)
 }
})
http.post('/user/bankQuickLogin', { openid: '1652454242' }).then(res => { console.log(res) })