npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

universal-request

v2.2.2

Published

用于发起网络请求

Downloads

418

Readme

universal-request npm

用于发起网络请求

安装

$ npm install universal-request --save

示例

import request from 'universal-request';

// 快应用中的引入方法
// import chooseImage from 'universal-request/lib/quickapp;

request({
  url: 'https://alibaba.github.io/rax/',
  method: 'POST',
  data: {
    from: 'Rax',
  },
  dataType: 'json'
}).then(response => {})
  .catch(error => {});

方法

request(options)

支持

参数

| 成员 | 类型 | 描述 | 必选 | 默认值 | | --- | --- | --- | --- | --- | | options | object  | | 是 | - | | opthons.url | string  | 请求的URL地址 | 是 | - | | opthons.headers | object  | 设置请求的头部 | 否 | {  'Content-Type': 'application/json'} | | options.method | string  | 可用的值有:GET/POST/PUT/DELETE/PATCH/HEAD,小程序中仅支持GET/POST | 否 | GET  | | options.data | object  | - GET请求或POST请求设置headers['content-Type'] 为 application/x-www-form-urlencoded时会拼接到URL中- 其他情况请求会转换为JSON字符串以请求体的形式给服务端 | 否 | - | | options.timeout | number  | 超时时间 | 否 | 20000 (ms) | | options.data类型 | string  | 期望返回的数据格式, json 或者 text ,若转换失败,则原样返回 | 否 | json  |

返回

请求成功返回:Promise<Response>

| 成员 | 类型 | 描述 | | --- | --- | --- | | response | object | - | | response.data | string  | 请求返回数据,按照dataType中声明的类型转换,若转换失败则原样返回 | | response.headers | object  | 请求的返回头部,JSONP请求无值 | | response.status | number  | 请求返回的状态码,JSONP请求无值 |

请求失败返回:

| 成员 | 类型 | 描述 | | --- | --- | --- | | error | object | - | | error.code | number  | 错误码 | | error.message | string  | 错误说明 |

错误码:

| code | message | 说明 | | --- | --- | --- | | 0 | 请求失败的详细说明 | 除以下列出请求外的,请求失败 | | 1 | Request timeout | 请求超时 | | 2 | Request not support this platform | 不支持该平台 |