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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cherry-rest

v0.0.5

Published

一种非常优雅Rest接口调用方式 ## Features

Readme

CherryRest

一种非常优雅Rest接口调用方式

Features

  • 基于Restful风格接口设计的模块化接口url生成器
  • 集中管理接口url
  • 默认使用fetch作为接口加载器
  • 可以给模块单独设置baseUrl
  • 支持response formatter配置、支持单个module formatter
  • 内置默认filter,当前只有一个over,重载response data filed

Install

npm install cherry-rest --save

Usage

import Cherry,{module as CherryModule,config as CherryConfig} from 'cherry-rest'

基于业务Rest接口定义模块

//方式一
CherryModule('name');

//方式二、定义多个模块、模块设置别名
CherryModule('module2|home,moudle3|user');

//方式三、复合继承模式
CherryModule([{
    name:'module3',
    alias:'about',
    children:[{
        name:'info',
    },{
        name:'concat'
    }]
}]);

调用

Cherry.module3.info.query({query:{id:1}}).then(res=>res)
//fetch get /about/info?id=1;
Cherry.module3.info.create({body:{name:1}}).then(res=>res)
//fetch post /about/info {name:1};
Cherry.module3.info.update({query:{id:1}}).then(res=>res)
//fetch put /about/info?id=1;
Cherry.module3.info.remove({path:'1,2'}).then(res=>res)
//fetch delete /about/info/1/2;

Test

import Cherry,{module as CherryModule,config as CherryConfig} from '../dist/index.js'
//http://ip.taobao.com/service/getIpInfo.php?ip=114.114.114.114
jest.setTimeout(1200000);

CherryConfig({
    credentials:'include'
},{
    baseUrl:'http://ip.taobao.com',
    formatter:function(res){
        return res.json()
    }
})

CherryModule('ip|service',{
    formatter:[function(data){
        return data.data;
    }],
    filters:[{
        name:'over',
        options:['city_id|id']
    }]
});

it('async & filters test', () => {
    expect.assertions(1);
    return Cherry.ip.query({path:'getIpInfo.php',query:{ip:'114.114.114.114'}}).then(data => {
        expect(JSON.stringify(data)).toEqual(JSON.stringify({"id":"320100"}))
    });
});

Demo

Base

API Example:

get http://www.baidu.com/mock/v1/user

get http://www.baidu.com/mock/v1/user?id=${userId}

get http://www.baidu.com/mock/v1/user/${userId}/blogs

get http://www.baidu.com/mock/v1/books

post http://www.baidu.com/mock/v1/user {name:'hello'}

put http://www.baidu.com/mock/v1/user/{userId} {name:'world'}

//import
import Cherry,{module as CherryModule,config as CherryConfig} from 'cherry-rest'

//基于rest业务接口定义模块
//配置baseUrl
CherryConfig({
    //默认使用fetch请求数据、这里可以配置fetch
    fetch:{},
    common:{
        baseUrl:'http://www.baidu.com'
    }
})

//定义模块
CherryModule([{
    name:'app',
    alias:'mock',
    children:[{
        name:'version',
        alias:'v1',
        children:[{
            name:'user'
        },{
            name:'books'
        }]
    }]
}])

let User=Cherry.app.version.user;
let Book=Cherry.app.version.app;

//GET http://www.baidu.com/mock/v1/user
User.query()

//GET http://www.baidu.com/mock/v1/user?id=123
User.query({query:{id:'123'}})

//POST http://www.baidu.com/mock/v1/user {name:'hello'}
User.create({body:{name:'hello'}})

//PUT http://www.baidu.com/mock/v1/user/123 {name:'world'}
User.update({path:'123',body:{name:'world'}})

//GET http://www.baidu.com/mock/v1/user/${userId}/blogs
User.query({path:['123','blogs'])

//DELETE http://www.baidu.com/mock/v1/user/123
User.remove({path:'123')