https://github.com/emileber/axios-resource
Simple Axios REST resource class
https://github.com/emileber/axios-resource
axios http resource rest
Last synced: 7 months ago
JSON representation
Simple Axios REST resource class
- Host: GitHub
- URL: https://github.com/emileber/axios-resource
- Owner: emileber
- License: mit
- Created: 2018-02-16T16:25:40.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T23:14:14.000Z (about 3 years ago)
- Last Synced: 2024-10-29T20:53:11.380Z (over 1 year ago)
- Topics: axios, http, resource, rest
- Language: JavaScript
- Homepage: https://emileber.github.io/axios-resource/
- Size: 483 KB
- Stars: 4
- Watchers: 3
- Forks: 4
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# axios-resource
[](https://travis-ci.org/emileber/axios-resource)
[](https://beta.gemnasium.com/projects/github.com/emileber/axios-resource)
[](https://www.npmjs.com/package/axios-resource)
Simple [axios](https://github.com/axios/axios) resource class to easily interact with a REST endpoint.
Explore [**the documentation**](https://emileber.github.io/axios-resource/).
## Requirements
- axios
## Installation
```bash
npm install --save axios-resource
```
## Getting started
Create a simple implementation of a resource endpoint.
```javascript
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).
```javascript
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.
```javascript
import API from './api';
// GET http://example.com/user/me
API.user.fetch('me').then(({ data }) => {
// data is the user attributes.
})
```