Registry / devops / rest-api-path

rest-api-path

JSON →
library1.1.10jsnpmunverified

A lightweight frontend library (v1.1.10, stable, semantic-release) for generating REST API request metadata (method, URI, params, data, delay) without making actual HTTP requests. Designed for Vue/Nuxt, it supports configurable resources with optional base URL, prefix, version, routing templates, and an authorization key. Its key differentiators: declarative resource configuration, custom methods (cget, load, save, etc.), and a built-in query delay feature for UI responsiveness testing. Not a HTTP client; use alongside fetch/axios.

npm install rest-api-path
INSTALL
IMPORT
SIG · REST-API-PATH
R
rest-api-path
devopsjavascriptv1.1.10
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 'rest-api-path'
const Api = require('rest-api-path')
Default export. Works in ESM environments; CommonJS require not officially supported.
Api (TypeScript)
import Api from 'rest-api-path'
import { Api } from 'rest-api-path'
No named export 'Api'; only default export. TypeScript users must use default import.
ResourceConfig
import type { ResourceConfig } from 'rest-api-path'
import { ResourceConfig } from 'rest-api-path'
TypeScript type export; not a runtime value. Use type import for type-checking resource configs.

Shows how to instantiate Api with resource configuration, generate GET and POST request objects without making HTTP calls.

import Api from 'rest-api-path'; const api = new Api({ default: { host: 'https://api.example.com', prefix: 'v1' }, users: { routing: { get: '{id}', cget: '', post: '', put: '{id}', delete: '{id}' } } }); // Generate a GET request to /v1/users/123 const req = api.res('users').get({ id: 123 }); console.log(req); // { // method: 'get', // uri: '/v1/users/123', // params: {}, // data: null, // seconds: 0 // } // Generate a POST request to /v1/users const createReq = api.res('users').post(null, { name: 'Alice' }); console.log(createReq); // { // method: 'post', // uri: '/v1/users', // params: {}, // data: { name: 'Alice' }, // seconds: 0 // }
Debug
Known issues
gotchaThe get() method requires an id parameter by default; use load() for requests without id.
fix
Use api.res('users').load(null, '/users') instead of get() when no ID is needed.
affects: >=1.0.0
gotchaThe constructor expects an object with string keys; using an array will not assign default resource correctly.
fix
Pass an object: { default: { host: '...' }, users: { ... } }.
affects: >=1.0.0
gotchaResource methods (get, post, etc.) do NOT return Promises; they return plain objects. Cannot await them.
fix
Use the returned object as request config for a separate HTTP client (axios, fetch).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: api.res(...).get is not a function
Missing 'routing' definition for the resource; default routing may not include custom method.
fix
Ensure the resource config includes a 'routing' object with the method key (e.g., get: '{id}').
Uncaught TypeError: Cannot read properties of undefined (reading 'host')
No 'default' resource defined in constructor config; library expects at least a default resource.
fix
Pass an object with a 'default' key hosting base configuration: new Api({ default: { host: '...' } }).
Error: Resource 'users' not found
Referencing a resource name that was not defined in the config passed to the constructor.
fix
Add the resource to the config object: { default: {...}, users: {...} }.
Upgrade
Version history
1.1.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
rest-api-path — npm install rest-api-path · libregistry