Registry / security / jwt-rest-api-client

jwt-rest-api-client

JSON →
library0.1.25jsnpmunverified

Promise-based HTTP client for browser and Node.js built on top of axios, focusing on JWT token lifecycle management. Version 0.1.25 provides an ApiClient class that extends axios with automatic token refresh, request deduplication, and Vue/Nuxt plugins. Unlike raw axios, it handles token storage, refresh logic, and concurrent request queuing out of the box.

npm install jwt-rest-api-client
INSTALL
IMPORT
SIG · JWT-REST-API-CLIEN
J
jwt-rest-api-client
securityjavascriptv0.1.25
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.

ApiClient
import { ApiClient } from 'jwt-rest-api-client'
const { ApiClient } = require('jwt-rest-api-client')
ESM is supported; CommonJS require may work but is not officially documented.
Vue3Plugin
import { Vue3Plugin } from 'jwt-rest-api-client/src/plugins'
import { Vue3Plugin } from 'jwt-rest-api-client/plugins'
Vue3Plugin is in src/plugins, not root.
ApiClient (default import)
import ApiClient from 'jwt-rest-api-client'
import { default as ApiClient } from 'jwt-rest-api-client'
The package exports both named and default exports.

Creates an ApiClient instance with base URL and token refresh endpoint, then performs a GET request with async/await and error handling.

import { ApiClient } from 'jwt-rest-api-client'; const apiClient = new ApiClient({ baseURL: 'https://api.example.com/', tokenRefreshEndpoint: '/auth/refresh', }); async function fetchData() { try { const response = await apiClient.get('/users', { headers: { Authorization: 'Bearer ' + process.env.TOKEN ?? '' } }); console.log(response.data); } catch (error) { console.error(error); } }
Debug
Known issues
gotchaToken storage relies on localStorage by default; not secure for sensitive apps.
fix
Implement a custom token storage adapter (e.g., using httpOnly cookies).
affects: >=0.1.0
gotchaVue3Plugin path is `jwt-rest-api-client/src/plugins`; using `jwt-rest-api-client/plugins` will result in module not found.
fix
Import from 'jwt-rest-api-client/src/plugins'.
affects: >=0.1.0
deprecatedThe package does not provide a React plugin as stated in README (marked TODO).
fix
Manually integrate ApiClient with React using hooks.
affects: >=0.1.0
gotchaRequest deduplication may cache failed requests if not configured properly.
fix
Set `deduplicate: false` in config or handle errors to invalidate cache.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'jwt-rest-api-client/src/plugins'
Vue3Plugin import path is incorrect
fix
Use correct path: import { Vue3Plugin } from 'jwt-rest-api-client/src/plugins'
TypeError: apiClient.get is not a function
Forgot to instantiate ApiClient with 'new'
fix
const apiClient = new ApiClient({...})
Token refresh loop: infinite requests to /auth/refresh
Refresh endpoint returns invalid token or fails to update stored token
fix
Ensure refresh endpoint returns a new token and update the token storage correctly
Upgrade
Version history
0.1.25latest on npm
Audit
Dependencies
axiosrequiredcore HTTP client
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
jwt-rest-api-client — npm install jwt-rest-api-client · libregistry