axios-resource

0.1.3 • Public • Published

axios-resource

Build Status Dependency Status npm version

Simple axios resource class to easily interact with a REST endpoint.

Explore the documentation.

Requirements

  • axios

Installation

npm install --save axios-resource

Getting started

Create a simple implementation of a resource endpoint.

import Resource from 'axios-resource';
 
export default class UserResource extends Resource {
    static URL = 'user/{id}';
}

Then expose the resource (e.g. through a service-like module).

import axios from 'axios';
import UserResource from './resources/user';
 
const http = axios.create({
    baseURL: 'http://example.com'
});
 
export default {
    user: new UserResource({ http })
}

You're ready to use this simple API service module.

import API from './api';
 
// GET http://example.com/user/me
API.user.fetch('me').then(({ data }) => {
    // data is the user attributes.
})

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.3207latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.3207
0.1.21
0.1.11
0.1.01

Package Sidebar

Install

npm i axios-resource

Weekly Downloads

210

Version

0.1.3

License

MIT

Unpacked Size

13.2 kB

Total Files

5

Last publish

Collaborators

  • emileber