1.5.2 • Published 2 years ago

@prequest/miniprogram v1.5.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@prequest/miniprogram

泛小程序请求库.支持各个小程序平台、快应用、鸿蒙

安装

npm install @prequest/miniprogram

使用

由于在不同平台上使用基本一致,所以基本使用文档,请查阅 这里

原生请求实例

import { PreQuest, create } from '@prequest/miniprogram'

const prequest = create(wx.request)

prequest('/api', {
  getNativeRequestInstance(nativeRequest) {
    nativeRequest.onHeadersReceived(res => {
      console.log('响应头', res.header)
    })
  },
})

兼容

小程序中使用 async/await 需要安装 regenerator-runtime@0.11.1,框架包一般会内置这个依赖,如果没有,请自行安装,使用方式请在对应论坛进行查找。此外,由于包都是 ES6 版本的,在某些手机上可能有兼容性问题,你可以查阅这里编译代码

请求配置项

!> 下面的列表中,PreQuest 只会处理标注为 👍 的参数,其他参数将直接传入到原生请求实例。这意味着,原生请求实例不支持的参数,传入其中将无效。

Option NameTypeDefaultRequiredHandleMeaning
pathstringnoneY👍server interface path
methodstringGETN👎request method
baseURLstringnoneN👍base server interface address
getNativeRequestInstance(value: Promise\<any>) => voidnoneN👍get native request instance
cancelTokenCancelTokennoneN👍cancel a request
timeoutnumbernoneN👎request timeout
paramsobjectnoneN👍url parameters
dataobjectnoneN👎the data to be sent as the request body
responseTypejson | text | arraybuffer |...noneN👎response data type
headerobjectnoneN👎set the request header
dataTypejson | ...noneN👎returned data format

此外,你也可以添加一些原生 API 支持的配置项,这部分配置项将会直接传递到原生 API 方法中。

示例:

declare module '@prequest/types' {
  interface PQRequest {
    enableHttp2?: boolean
    enableCache?: boolean
  }

  interface PQResponse {
    header: any
    cookies: string[]
    profile: any
  }
}

const instance = create(wx.request, {
  baseURL: 'http://localhost:3000'
  enableHttp2: true // You can get intelliSense here
})

// You can get intelliSense here
instance.use(async (ctx, next) => {
  ctx.request.enableHttp2
  await next()
  ctx.response.header
})
1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.10

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.3-alpha.0

2 years ago

1.2.6

2 years ago

1.2.4

3 years ago

1.2.0

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.2.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.1-alpha.0

3 years ago

1.0.0-alpha.0

3 years ago

0.4.7

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.6

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.2

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.7

3 years ago

0.2.8

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.9

3 years ago

0.1.6

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago