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

resource-axios

v1.2.5

Published

create vue-resource's resource like object

Downloads

45

Readme

resource-axios

npm version build status code coverage npm downloads code helpers FOSSA Status

Create vue-resource's resource like object. Restful methods, interceptors support.

Installation

npm i -S resource-axios
npm i -S axios

Usage

import resource from 'resource-axios';
import axios from 'axios';

const Book = resource('/api/books', axios);

// get book of id:1 =>  curl '/api/books/1'
Book.get(1).then(res => console.log(res));
Book.get({ id: 1 }).then(res => console.log(res));
Book.get({ _id: 1 }).then(res => console.log(res));

// query books name:foo => curl '/api/books?name=foo'
Book.query({ name: 'foo' }).then(res => console.log(res));

// add book of id:1 => curl -H "Content-Type:application/json" -X POST --data '{"name":"foo"}' /api/books
Book.save({ name: 'foo' }).then(res => console.log(res));
Book.post({ name: 'foo' }).then(res => console.log(res));

// update book of id:1 => curl -H "Content-Type:application/json" -X PUT --data '{"name":"foo"}' /api/books/1
Book.update(1, { name: 'foo' }).then(res => console.log(res));
Book.update({ id: 1, name: 'foo' }).then(res => console.log(res));
Book.put(1, { name: 'foo' }).then(res => console.log(res));
Book.put({ id: 1, name: 'foo' }).then(res => console.log(res));

// delete book of id:1 => curl -X DELETE /api/books/1
Book.delete(1).then(res => console.log(res));
Book.delete({ id: 1 }).then(res => console.log(res));
Book.del(1).then(res => console.log(res));
Book.del({ id: 1 }).then(res => console.log(res));

Customize actions

Axios doc: axios-api

import resource from 'resource-axios';
import axios from 'axios';

const Book = resource('/api/books', {
  sell: (id) => axios.get(`/api/books/${id}/sell`),
}, axios);

// sell book of id:1 => curl /api/books/1/sell
Book.sell(1).then(res => console.log(res));

Interceptors

Axios doc: interceptors

import resource from 'resource-axios';
import axios from 'axios';

const Book = resource('/api/books', axios);
// const Book = resource('/api/books', { /* customized actions */ }, axios);

// Add a request interceptor
axios.interceptors.request.use((config) => {
  // Do something before request is sent
  console.log(config);
  return config;
});

// Add a response interceptor
axios.interceptors.response.use((response) => {
  // Do something with response data
  console.log(response);
  return response;
});

// get book of id:1 =>  curl '/api/books/1'
Book.get(1);

Changelog

version | log ------------ | ------------- v1.2.1 | support more params format; params error will be throw out; add post and put methods changelog v1.1.2 | add notice when axios is not imported v1.1.1 | refactoring codes v1.1.0 | remove axios self-injecting. changelog v1.0.16 | fix issue#1

License

MIT

Copyright (c) 2018-present, liuyanzhi08

FOSSA Status