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

@uni/request

v1.1.9

Published

[![npm](https://img.shields.io/npm/v/@uni/request.svg)](https://www.npmjs.com/package/@uni/request)

Downloads

92

Readme

request

npm

Used to initiate a network request Note: This API does not support promise calls

Supported

Install

$ npm install @uni/request --save

or

$ npm install @uni/apis --save

Usage

import { request } from '@uni/apis';

request({
  url: 'https://alibaba.github.io/rax/',
  method: 'POST',
  data: {
    from: 'Rax',
  },
  dataType: 'json',
  success: (res) => {
    console.log('success', res);
  },
  fail: (res) => {
    console.log('fail', res);
  },
  complete: (res) => {
    console.log('complete', res);
  }
});

request({
  url: 'http://suggest.taobao.com/sug',
  method: 'JSONP',
  data: {
    code: 'utf-8',
    q: '卫衣'
  },
  jsonpCallback: 'cb',
  jsonpCallbackProp: 'callback',
  timeout: 5000,
  success: (res) => {
    console.log('success', res);
  },
  fail: (res) => {
    console.log('fail', res);
  },
  complete: (res) => {
    console.log('complete', res);
  }
});

You can also import from the big package:

import { request } from '@uni/apis';

Arguments

| Property | Type | Description | Required | Default | | --- | --- | --- | --- | --- | | options | object  | | true | - | | options.url | string  | Required,the request url | true | - | | options.headers | object  | The request headers | false | {  'Content-Type': 'application/json'} | | options.method | string  | Values:GET/POST/PUT/DELETE/PATCH/HEAD/JSONP,mini app only support GET/POST/JSONP | false | GET  | | options.data | object  | - GET or POST set headers['content-Type'] is equal to application/x-www-form-urlencoded data will apply to URL- In other cases, the data will be converted to a JSON string as request body to the server. | false | - | | options.timeout | number  | timeout | false| 20000 (ms) | | options.dataType | string  | Set return data type, json or text, If the conversion fails, returns as it is | false | json  | | options.jsonpCallback | string  | The callback method name of jsonp, which only takes effect when method is JSONP | false | __uni_jsonp_handler  | | options.jsonpCallbackProp | string  | The name of the callback attribute of jsonp, which only takes effect when the method is JSONP | 否 | callback  | | options.success | Function  | The callback function for a successful API call | false | - | | options.fail | Function  | The callback function for a failed API call | false | - | | options.complete | Function  | The callback function used when the API call completed (always executed whether the call succeeds or fails) | 否 | - |

Non-universal parameters (due to destroying the ability of one code and multiple terminals, it is not recommended to use)

| Property | Type | Default | Required | Description | Supported | | ------ | -------- | ------ | ---- | ----- | ------- | | responseType | string | text | x | 响应的数据类型 | | | enableHttp2 | boolean | false | x | 开启 http2 | | | enableQuic | boolean | false | x | 开启 quic | | | enableCache | boolean | false | x | 开启 cache | | | cloudCache | object/boolean | false | x | 开启云加速 | |

Success return:Response

| Property | Type | Description | | --- | --- | --- | | response | object | - | | response.data | string  | The data returned by the request is converted according to the type declared in the dataType. If the conversion fails, it is returned as it is | | response.headers | object  | Response headers | | response.status | number  | Response status |

Non-universal return parameters (due to the destruction of the ability of one code, it is not recommended to use)

| Property | Type | Description | Supported | | ------ | -------- | ----- | ------- | | cookies | Array.<string> | The cookies returned by the developer server, in the format of a string array | | | profile | Object | Some debugging information during the network request | |

Fail return:

| Property | Type | Description | | --- | --- | --- | | error | object | - | | error.code | number  | Error code | | error.message | string  | Error message |

RequestTask

Request task object

Function

RequestTask.abort() Interrupt request task

Not a universal method (due to the destruction of the ability of one code, it is not recommended to use)

Only WeChat supports the following methods RequestTask.onHeadersReceived(function callback) Listen to the HTTP Response Header event. Will be completed earlier than the requested completion event

RequestTask.offHeadersReceived(function callback) Cancel listening for HTTP Response Header event