{"id":47588,"library":"fetch-factory","title":"fetch-factory","description":"A wrapper around the native fetch API to simplify creating service objects for REST APIs. Version 0.2.1 is the latest stable release. This library is in maintenance mode with no recent updates. It provides a declarative way to define API endpoints, supports parameter interpolation, JSON handling for POST requests, and request interceptors. Unlike heavier HTTP clients, fetch-factory is lightweight and relies on native fetch and Promise, requiring polyfills for older environments. It is consumable in Node.js and browsers via bundlers.","status":"maintenance","version":"0.2.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install fetch-factory","lang":"bash","label":"npm"},{"cmd":"yarn add fetch-factory","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetch-factory","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required in older browsers that do not natively support the fetch API.","package":"whatwg-fetch","optional":true},{"reason":"Required in older environments that do not natively support Promises.","package":"es6-promise","optional":true}],"imports":[{"note":"Default import is used. CommonJS require works but TypeScript may prefer ES module syntax.","wrong":"const fetchFactory = require('fetch-factory')","symbol":"fetchFactory","correct":"import fetchFactory from 'fetch-factory'"},{"note":"create is a method on the default export, not a named export.","wrong":"import { create } from 'fetch-factory'","symbol":"fetchFactory.create","correct":"import fetchFactory from 'fetch-factory'; const factory = fetchFactory.create(config)"},{"note":"For browser builds using the distribution file, fetchFactory is available globally.","wrong":"import fetchFactory from 'fetch-factory' // Not needed in browser bundle","symbol":"global.fetchFactory","correct":"// In browser builds, use the global variable directly: const factory = window.fetchFactory.create(config)"}],"quickstart":{"code":"import fetchFactory from 'fetch-factory';\n\nconst Users = fetchFactory.create({\n  url: 'https://api.example.com/users/:id',\n  methods: ['find', 'create']\n});\n\n// GET https://api.example.com/users\nUsers.find().then(response => response.json()).then(console.log);\n\n// GET https://api.example.com/users/123\nUsers.find({ params: { id: 123 } }).then(response => response.json()).then(console.log);\n\n// POST https://api.example.com/users with JSON body { name: 'Jack' }\nUsers.create({ data: { name: 'Jack' } }).then(response => response.json()).then(console.log);","lang":"javascript","description":"Demonstrates basic usage of fetch-factory to create a REST client with find and create methods, including parameter substitution and JSON body for POST."},"warnings":[{"fix":"Install and import 'whatwg-fetch' and 'es6-promise' polyfills before using fetch-factory.","message":"You must have a global fetch and Promise available. In Node.js versions <18 or older browsers, you need polyfills.","severity":"gotcha","affected_versions":">=0"},{"fix":"Use a request interceptor to modify headers or consider a different library for non-JSON payloads.","message":"POST requests automatically set Content-Type to application/json and stringify the data object. If you need to send form data or other types, you cannot override these default headers within the current configuration.","severity":"gotcha","affected_versions":">=0"},{"fix":"Always return an object with the three required properties, or clone the request and modify.","message":"The interceptors.request function must return an object with headers, body, and method properties. If you return the original request object directly, it may not include these properties correctly.","severity":"gotcha","affected_versions":">=0"}],"env_vars":null,"search_vec":"'0.2.1':20 'api':10,18,43 'around':6 'browser':83 'bundler':85 'client':59 'consum':79 'creat':13 'declar':39 'defin':42 'endpoint':44 'environ':76 'factori':3,62 'fetch':2,9,61,69 'fetch-factori':1,60 'handl':49 'heavier':57 'http':58 'interceptor':55 'interpol':47 'javascript':86 'json':48 'latest':23 'librari':27 'lightweight':64 'mainten':30 'mode':31 'nativ':8,68 'node.js':81 'object':15 'older':75 'paramet':46 'polyfil':73 'post':51 'promis':71 'provid':37 'recent':34 'releas':25 'reli':66 'request':52,54 'requir':72 'rest':17 'servic':14 'simplifi':12 'stabl':24 'support':45 'unlik':56 'updat':35 'version':19 'via':84 'way':40 'wrapper':5","created_at":"2026-06-07T16:52:17.502995+00:00","updated_at":"2026-06-07T16:52:17.502995+00:00","problems":[{"fix":"Ensure the fetch-factory script is loaded (dist/fetch-factory.js) or import the module correctly in your bundler.","cause":"Attempting to use the library without importing it correctly (e.g., using the browser global without including the script).","error":"fetchFactory is not defined"},{"fix":"Run `npm install fetch-factory` to install the package.","cause":"The package is not installed or not available in node_modules.","error":"Cannot find module 'fetch-factory'"},{"fix":"Install a fetch polyfill like 'whatwg-fetch' and import it before using fetch-factory.","cause":"The fetch API is not available globally, possibly due to missing polyfill or running in an unsupported environment.","error":"Unhandled Promise rejection: TypeError: Failed to fetch"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"fetch-factory","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}