Axios Rest
A simple axios wrapper to make rest api call delightful.
Example
const axiosRestClient = const api = // Get all usersapiusersall // Create new userapiusers
Installation
npm install --save axios-rest-client
axios-rest require axios to work, so you have to install axios
npm install --save axios
How to use it ?
Create your axios rest client
const axiosRestClient = const api =
And that all ! You can start requesting your api
Start by creating endpoint for your resources
// Create multiple resources endpointsapi api // Create /users endpoint // You can access previously endpoint as attribute// If the endpoint does not exist it will be created automaticallyapiusersapicomments // get endpoint for comments on /comments
You can then call
apiusersall // GET /usersapiusers // Get /users/1apiusers // POST /users, body=dataapiusers // PUT /users/1, body=dataapiusers // DELETE /users/1
If you want to create an api endpoint for a single instance of a collection just call .one(instanceId) on the collection endpoint.
apiusers // Create entity endpoint for user with id 1// or simply doapiusers1 // to get the /users/1 endpoint automatically created for you
You can the call
apiusers1 // GET /users/1apiusers1 // POST /users/1, body = dataapiusers1 // PUT /users/1, body = dataapiusers1 // DELETE /users/1