Registry / devops / modelproxy-engine-fetch

modelproxy-engine-fetch

JSON →
library3.0.31jsnpmunverified

A fetch-based engine for the modelproxy library, enabling HTTP requests via the Fetch API. Version 3.0.31 is current. This engine provides timeout, cache (in-memory with optional expiration), and reload features. It is designed to work with the modelproxy proxy system, allowing middleware-like request/response interception. Compared to other engines like AxiosEngine, this one leverages the built-in fetch, reducing dependencies. Release cadence is irregular; updates focus on bug fixes and compatibility.

npm install modelproxy-engine-fetch
INSTALL
IMPORT
SIG · MODELPROXY-ENGINE-
M
modelproxy-engine-fetch
devopsjavascriptv3.0.31
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.

FetchEngine
import { FetchEngine } from 'modelproxy-engine-fetch'
const FetchEngine = require('modelproxy-engine-fetch')
Default CommonJS require is incorrect because the package exports a named export. Use ESM import or destructure require.
type FetchEngine
import type { FetchEngine } from 'modelproxy-engine-fetch'
TypeScript users can import only the type for type-checking without runtime import.
Instance
import { FetchEngine } from 'modelproxy-engine-fetch'; const engine = new FetchEngine()
const engine = new (require('modelproxy-engine-fetch').FetchEngine)()
Constructor usage is straightforward; ensure to call init() after instantiation.

Initializes a FetchEngine, adds a middleware to validate HTTP status and response data code, then registers it with modelproxy Proxy.

import { FetchEngine } from 'modelproxy-engine-fetch'; import { Proxy } from 'modelproxy'; const fetchEngine = new FetchEngine(); fetchEngine.init(); // Add middleware to check status and data code fetchEngine.use(async (ctx, next) => { if (ctx.result.status !== 200) { throw new Error(ctx.result.statusText); } ctx.result = await ctx.result.clone(); const serData = await ctx.result.json(); if (serData.code !== 200) { throw new Error(serData.message); } await next(); }); const proxy = new Proxy(); proxy.addEngines({ react: fetchEngine }); // Example usage: proxy.execute('someKey', { ... })
Debug
Known issues
gotchaFetch result body can only be read once. Must clone the response before reading.
fix
Use ctx.result.clone() before calling .json() or .text() on the response.
affects: all
gotchaMiddleware exec order: the engine uses a middleware pipeline. If next() is not called, subsequent middleware won't execute.
fix
Call await next() in each middleware to continue the pipeline.
affects: all
deprecatedThe release cadence is irregular; no active development since 2022.
fix
Consider migrating to other engines like modelproxy-engine-axios if active maintenance is needed.
affects: >=3.0.0
gotchaCache is in-memory only and non-persistent. Setting expire does not persist across requests.
fix
Use an external caching layer if persistence is required.
affects: all
Errors
Common errors & fixes
TypeError: Body already read
Calling response.json() twice without cloning the response.
fix
Use ctx.result = await ctx.result.clone(); before reading.
TypeError: ctx.result is not a Response
Middleware may have set ctx.result to something else (e.g., parsed JSON) before next middleware runs.
fix
Ensure middleware does not replace ctx.result prematurely; clone and preserve Response type.
Error: Timeout of 5000ms exceeded
Request took longer than default timeout.
fix
Increase timeout via settings: new FetchEngine({ settings: { timeout: 10000 } })
Upgrade
Version history
3.0.31latest on npm
Audit
Dependencies
modelproxyoptionalPeer dependency: the engine integrates with modelproxy's Proxy and engine system.
Agent activity
4 hits · last 30 days
node
2
Amazon
1
Bingbot
1
Resources
modelproxy-engine-fetch — npm install modelproxy-engine-fetch · libregistry