Registry / devops / fetch-service-parser

fetch-service-parser

JSON →
library0.2.16jsnpmunverified

A lightweight HTTP client built on the Fetch API with whatwg-fetch polyfill. It simplifies defining RESTful endpoints with support for path parameters, file uploads, custom headers (JSON, Form URL-encoded), request queuing, mock data, response parsing, parameter validation, and global error events. Version 0.2.16. Low release cadence. Ships TypeScript types. Differentiators: integrated mocking, useQueue option for sequential requests, and built-in content type constants. Suitable for React and Node environments.

npm install fetch-service-parser
INSTALL
IMPORT
SIG · FETCH-SERVICE-PARS
F
fetch-service-parser
devopsjavascriptv0.2.16
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.

services
import { services } from 'fetch-service-parser'
import services from 'fetch-service-parser'
Named export, not default. Contains parseRequest and event methods.
parseRequest
import { services } from 'fetch-service-parser'; const { parseRequest } = services
import { parseRequest } from 'fetch-service-parser'
parseRequest is a property of the services object, not a direct export.
CONTENT_TYPES
import { CONTENT_TYPES } from 'fetch-service-parser'
import { contentTypes } from 'fetch-service-parser'
Named export with uppercase keys: JSON, FORM_URL, etc.

Shows defining two endpoints using parseRequest, configuring method and headers with CONTENT_TYPES, then calling List with query params.

// api.js import { services, CONTENT_TYPES } from 'fetch-service-parser'; const { parseRequest } = services; export const List = parseRequest({ url: '/api/list', }); export const Create = parseRequest({ url: '/api/create', method: 'POST', headers: { 'Content-Type': CONTENT_TYPES.FORM_URL, }, }); // usage.js import { List } from './api.js'; List({ pageIndex: 1, pageSize: 10 }) .then(items => console.log(items)) .catch(err => console.error(err));
Debug
Known issues
gotchaparseRequest is not directly exported; it must be accessed via services.parseRequest
fix
Use: import { services } from 'fetch-service-parser'; const { parseRequest } = services;
affects: >=0.0.0
gotchaExporting List as arrow function with parseRequest may cause tree-shaking issues if named export is mistaken for a React component
fix
Ensure the export is used as a function call (List(params)) not as JSX element.
affects: >=0.0.0
gotchaError event 'error' is global and noErrorTip does not prevent the event from being emitted; it only suppresses UI alerts
fix
To completely ignore errors, do not attach an 'error' listener, or filter errors inside the listener.
affects: >=0.0.0
gotchaThe mock option only works when debug is true; it's easy to forget setting debug: true
fix
Set debug: true in the configuration or pass it in parseRequest options.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: services.parseRequest is not a function
importing services incorrectly (default import instead of named import)
fix
Use: import { services } from 'fetch-service-parser';
Uncaught (in promise) TypeError: Failed to fetch
whatwg-fetch polyfill not loaded when running in environments without native fetch (e.g., Node < 18, IE)
fix
Install and import whatwg-fetch before using fetch-service-parser: import 'whatwg-fetch'; or add polyfill to entry point.
Mock data was not used even though mock option was provided
debug option not set to true
fix
Add debug: true to the parseRequest configuration: parseRequest({ url: '...', mock: {...}, debug: true })
Content-Type header was not applied as expected
Using CONTENT_TYPES constant incorrectly (e.g., lowercased or wrong import)
fix
Import CONTENT_TYPES correctly: import { CONTENT_TYPES } from 'fetch-service-parser'; and use like CONTENT_TYPES.FORM_URL
Upgrade
Version history
0.2.16latest on npm
Audit
Dependencies
whatwg-fetchoptionalUsed as polyfill for fetch API in environments where fetch is not available (e.g., older browsers, Node.js < 18)
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-service-parser — npm install fetch-service-parser · libregistry