Registry / storage / restful-queue

restful-queue

JSON →
library1.0.103jsnpmunverified

A lightweight queue for service workers that buffers non-GET requests (POST, PUT, DELETE, etc.) and retries them when connectivity is restored. Current stable version is 1.0.103, released occasionally via commits to main. It leverages IndexedDB for persistent storage inside service workers and provides a simple API to queue and replay requests. Differentiates from similar libraries (like Workbox Background Sync) by being minimal, dependency-free, and focused purely on REST API calls.

npm install restful-queue
INSTALL
IMPORT
SIG · RESTFUL-QUEUE
R
restful-queue
storagejavascriptv1.0.103
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.

queueAndAttemptRequest
import { queueAndAttemptRequest } from 'restful-queue';
const queueAndAttemptRequest = require('restful-queue');
ESM-only; CommonJS require will fail. Use import syntax in service workers.
processQueue
import { processQueue } from 'restful-queue';
import processQueue from 'restful-queue';
Named export, not default. Remove curly braces for default import? No, it's named.
default
import * as restfulQueue from 'restful-queue';
import restfulQueue from 'restful-queue';
No default export; use namespace import to access all exports.

Intercepts non-GET fetch events, queues them if offline, and replays when online.

// In service worker import { queueAndAttemptRequest } from 'restful-queue'; self.addEventListener('fetch', event => { if (event.request.method !== 'GET') { event.respondWith(queueAndAttemptRequest(event.request)); } else { // Handle GET requests } });
Debug
Known issues
gotchaQueue only available inside a Service Worker context; will throw if used in main thread.
fix
Use only within service worker (self.addEventListener('fetch', ...)).
affects: <=1.0.103
gotchaNo built-in retry backoff or exponential backoff; all queued requests are replayed immediately when online.
fix
Implement custom retry logic or use a library like Workbox Background Sync.
affects: <=1.0.103
gotchaIndexedDB storage quota may be exceeded on some browsers; no eviction policy implemented.
fix
Monitor quota usage or manually purge old requests using deleteQueue() if exposed.
affects: <=1.0.103
gotchaOnly replays queued requests when the service worker is active; no sync event registration.
fix
Combine with Background Sync API for automatic replay when online.
affects: <=1.0.103
Errors
Common errors & fixes
Uncaught ReferenceError: self is not defined
Running queueAndAttemptRequest outside of Service Worker scope.
fix
Ensure code runs only inside a service worker file.
Failed to execute 'importScripts' on 'WorkerGlobalScope': The script 'restful-queue' has an unsupported MIME type.
Using importScripts with ESM module import.
fix
Use ES module import via <script type="module"> or import in service worker with 'import { ... } from "restful-queue";'.
TypeError: Failed to fetch (or similar CORS error) when replaying request
Queued request originally sent to a different origin; replay fails due to CORS.
fix
Ensure same-origin requests or configure CORS on the target server.
Upgrade
Version history
1.0.103latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
20
Resources
restful-queue — npm install restful-queue · libregistry