The Wayback Machine - https://web.archive.org/web/20201128023033/https://github.com/FrancescoSaverioZuppichini/API-Class
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Jul 24, 2019
Jul 24, 2019
Aug 16, 2017
Aug 16, 2017
Jul 24, 2019

README.md

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.

const myAPI = new API({ url: '/api' })

Endpoints

To add an endpoint, use the .createEntity method.

const myAPI = new API({ url: '/api' })
myAPI.createEntity({ name : 'posts' })
myApi.endpoints.posts.getAll()

Methods

All API's endpoints have basic CRUD operations

getAll(params, config)
getOne({ id }, config)
create(toCreate, config)
update(toUpdate, config)
delete({ id }, config)

Q&A

How to pass headers to axios?

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 informations

https://medium.com/@FrancescoZ/how-to-call-api-in-a-smart-way-2ca572c6fe86

About

A utility class for calling apis CRUD methods

Topics

Resources

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  
You can’t perform that action at this time.