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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cans-plugin-http

v0.0.6

Published

HTTP (axios) plugin for cans

Readme

cans-plugin-http

npm circle

HTTP (axios) plugin for cans

Install

$ yarn add cans-plugin-http

Usage

httpPlugin

Example

import cans from 'cans'
import { observable, action } from 'cans/mobx'
import { httpPlugin } from 'cans-plugin-http'

const app = cans()

app.use(httpPlugin)

app.model({
  observable: app => {
    return observable({
      list: [],

      fetchList: action.bound(async function () {
        const list = (await app.http.get('/api/v1/lists')).data
        // modify `list`
      })
    })
  }
})

options

  • axiosConfig: AxiosConfig. If provided, app.http will return axios.create(axiosConfig)

restPlugin

restPlugin is useful when your backend exposed frontend a standard RESTful interface. restPlugin will help you generate RESTful cans model that return a observable, which contains RESTful action and loading status:

Method | Path | action -------|-----------------|---------------- GET | /posts | app.models.rest.posts.index GET | /posts/:id | app.models.rest.posts.show POST | /posts | app.models.rest.posts.create PUT | /posts/:id | app.models.rest.posts.update DELETE | /posts/:id | app.models.rest.posts.delete

(Inspired by Egg)

Example

import cans from 'cans'
import { observable, action } from 'cans/mobx'
import { restPlugin } from 'cans-plugin-http'

const app = cans()

const URL = 'http://jsonplaceholder.typicode.com'

app.use(restPlugin, { 
  resources: [
    { name: 'posts', url: URL }
  ]
})

const PostList = ({ posts }) => (
  <div>
    {posts.map(post => (
      <h1>{post.title}</h1>
      <p>{post.body}</p>
    ))}
  </div>
)

const PostApp = inject(({ models }) => (
  <div>
    <button disable={models.rest.posts.loading.index} onClick={models.rest.posts.index}>Fetch</button>
    <PostList posts={models.rest.posts.data.index} />
  </div>
))

options

  • resources

    • name: resource name
    • url: endpoint URL
    • total: (AxiosResponse) => string | number - Compute total count from response
    • defaultData: { index: any, show: any } - Data fetched from rest[name].index will be set in rest[name].data.index. show is the same. index is [] by default. show is {} by default.

What in app.models.rest[name]

restPlugin create observables for every resource:

observable({
  // data fetched from RESTful interface
  data: {
    index: defaultData.index || [],
    show: defaultData.show || {}
  },
  // loading status
  loading: {
    index: boolean,
    show: boolean,
    create: boolean,
    update: boolean,
    delete: boolean
  },

  // action
  async index(),
  async show(id),
  async create(data),
  async update(id, data),
  async delete(id)
})

License

MIT License