Registry / devops / axios-rest-api

axios-rest-api

JSON →
library2.1.7jsnpmunverified

Simple Axios wrapper for REST API requests. Current stable version is 2.1.7. It provides a convenient abstraction over axios for making REST API calls with built-in resource routing, delay simulation, and support for multiple API servers. Key differentiators: custom HTTP methods (cget, load, save, etc.), configurable URL templates per resource, and built-in request delay for testing UI responsiveness. Requires axios and underscore as peer dependencies. Ideal for Vue.js applications.

npm install axios-rest-api
INSTALL
IMPORT
SIG · AXIOS-REST-API
A
axios-rest-api
devopsjavascriptv2.1.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Api
import Api from 'axios-rest-api'
const Api = require('axios-rest-api')
ESM default export only; CommonJS require is not supported.
instance
const api = new Api(resources)
const api = Api.create(resources)
Must use new keyword to instantiate; no static create method.
resources
import Api from 'axios-rest-api'; const resources = { default: { host: '...' } }; const api = new Api(resources);
const api = new Api({ host: '...' })
Configuration must be an array-like object with named resources, not a plain object.

Shows how to import and instantiate the Api class with default resource configuration, then perform GET requests using load() and get() methods.

import Api from 'axios-rest-api'; const resources = []; resources.default = { host: 'https://jsonplaceholder.typicode.com', prefix: '' }; const api = new Api(resources); // GET all posts api.res('default').load().then(response => { console.log(response.data); }).catch(error => { console.error(error); }); // GET post with id=1 api.res('default').get({ id: 1 }).then(response => { console.log(response.data); });
Debug
Known issues
gotchaConfiguration must be an array-like object with numbered indices for default resource or named resources. A plain object with only default will not work.
fix
Initialize resources as const resources = []; then assign resources.default = {...}; resources.users = {...};
affects: >=2.0.0
gotchamethod get() requires an id parameter by default; using it without id will cause a malformed URL. Use load() for requests without an id.
fix
For requests without id, use api.res('resource').load() instead of get().
affects: >=2.0.0
deprecatedThe library has not been updated since 2019; peer dependencies axios and underscore may have breaking changes in newer versions.
fix
Pin axios@0.19.x and underscore@1.9.x in your package.json to avoid compatibility issues.
affects: >=2.0.0
gotchaThe api.res() method returns a Resource instance; calling .load() without parameters will use the default resource route, which may be empty and result in a request to the base URL only.
fix
Always specify routing or use explicit URL as second parameter: api.res().load(null, 'https://example.com').
affects: >=2.0.0
Errors
Common errors & fixes
Uncaught TypeError: Cannot read property 'default' of undefined
resources array is not properly initialized or 'default' resource is not defined.
fix
Ensure const resources = []; and resources.default = { host: '...' }; before passing to new Api(resources).
TypeError: api.res is not a function
Instance created without new keyword or import is incorrect.
fix
Use import Api from 'axios-rest-api'; then const api = new Api();
GET http://127.0.0.1/undefined 404 (Not Found)
Missing id parameter in get() method results in URL with 'undefined' placeholder.
fix
Use api.res('users').get({id: 123}) or if no id needed, use .load().
Upgrade
Version history
2.1.7latest on npm
Audit
Dependencies
axiosrequiredHTTP client library used for making requests
underscorerequiredUtility library used for internal helper functions
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
axios-rest-api — npm install axios-rest-api · libregistry