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

hrsoft-ds

v0.0.8

Published

hrsoft 前后端通用网络请求库

Downloads

2

Readme

neuqer前后端通用网络请求库 hrsoft-ds

Overview

hrsoft-ds 是基于是基于fetch api 的一套前后端通用请求库,支持 get, post, delete, put 四种请求方式,默认请求头 Content-typeapplication/x-www-form-urlencoded

Advantages

  • 异步流程基于promise,解决了传统callback嵌套过深问题
  • 支持 url queryString 数组特殊处理
  • 支持 get 请求并发处理,实现前端 http 请求节流
  • ...

Installation

Npm

npm install hrsoft-ds --save

Bower

bower install hrsoft-ds --save

Usage

import ds from 'hrsoft-ds';
//or
const ds = require('hrsoft-ds');

GET

//register
ds.register('user.info', {
    type: 'get',
    url: '/user/info',
    headers:{}
});

//resolve
ds.resolve('user.info', {
     headers:{
       'Accept':'application/json'
     },
     qs:{
      id:1
     }
}).then(function(result) {
     console.log(result);
});

//or
ds.resolve('user.info', {
    id:1
}).then(function(result) {
     console.log(result);
});
  • 说明: ds.resolve(name,options),其中options兼容直接参数,如果是get || delete 方法,options里面的参数会最先替换掉registry里面的 path 参数,如 user/:id,则会先去查找options里面的 id 去替换 url 里面的 id,剩余参数默认带到url queryString里面去,如果是post || update 方法, 首先也会替换url 里面的 path 参数,但是剩余参数会默认带到请求 body 里面;

POST

//register
ds.register('user.login', {
    type: 'post',
    url: '/user/login',
    headers:{
        'Content-type': 'application/json'
    }
});

//resolve
ds.resolve('user.login', {
     headers:{
       'Accept':'application/json'
     },
     body:{
      name:'kuaizhan',
      password:'123456'
     }
}).then(function(result) {
     console.log(result);
});

//or
ds.resolve('user.login', {
    name:'kuaizhan',
    password:'123456'
}).then(function(result) {
     console.log(result);
});

Other

hrsoft-ds 内部重载了 Error 对象重载,可以通过捕获错误的错误码处理相应的错误

  • code:异常错误码 default :3
  • message:异常对应信息

错误码对应错误信息

| code | message | | -------|:------------------:| | 0 | 网络请求发生错误 | | 1 | 参数不正确 | | 2 | 请求方式不允许 | | 3 | 服务端返回数据格式不正确| | 4 | 未知错误 |
| 5 | 需要发布获取网络请求配置 |