Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/FrancescoSaverioZuppichini/API-Class
A utility class for calling apis CRUD methods
https://github.com/FrancescoSaverioZuppichini/API-Class
javascript webdevelopment
Last synced: about 2 months ago
JSON representation
A utility class for calling apis CRUD methods
- Host: GitHub
- URL: https://github.com/FrancescoSaverioZuppichini/API-Class
- Owner: FrancescoSaverioZuppichini
- Created: 2017-08-16T14:11:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T14:01:09.000Z (almost 2 years ago)
- Last Synced: 2024-07-17T08:26:40.803Z (2 months ago)
- Topics: javascript, webdevelopment
- Language: JavaScript
- Homepage:
- Size: 832 KB
- Stars: 89
- Watchers: 4
- Forks: 32
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# API Class
### faster way to generate API calls with axios## Installation
You can install the package using `npm````
npm install api-class
```https://www.npmjs.com/package/api-class
## Usage
Create an `API` instance by import the `API` class from `api-class`. As parameter pass the basic url of your api.```javascript
const myAPI = new API({ url: '/api' })
```
### Endpoints
To add an endpoint, use the `.createEntity` method.```javascript
const myAPI = new API({ url: '/api' })
myAPI.createEntity({ name : 'posts' })
myApi.endpoints.posts.getAll()```
### Methods
All `API`'s endpoints have basic CRUD operations```javascript
getAll(params, config)
getOne({ id }, config)
create(toCreate, config)
update(toUpdate, config)
delete({ id }, config)
```
### Q&AHow to pass headers to axios?
```javascript
const myAPI = new API({ url: '/api' })
myAPI.createEntity({ name : 'posts' })
myAPI.endpoints.posts({ id: 0 }, { headers: {....} } )
```
You can check it out my medium article for further informationshttps://medium.com/@FrancescoZ/how-to-call-api-in-a-smart-way-2ca572c6fe86