Registry / devops / piral-fetch

piral-fetch

JSON →
library1.11.0jsnpmunverified

Plugin for Piral that provides a standardized fetch API for pilets (microfrontends), with automatic authentication token injection and middleware support. Current stable version is 1.11.0, released as part of the Piral ecosystem with regular updates. Key differentiators: integrates with Piral's auth system, supports relative URLs to a configurable base URL, offers middleware pipeline for extending fetch behavior, and returns a slightly different response object than the browser fetch.

npm install piral-fetch
INSTALL
IMPORT
SIG · PIRAL-FETCH
P
piral-fetch
devopsjavascriptv1.11.0
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.

createFetchApi
import { createFetchApi } from 'piral-fetch'
const createFetchApi = require('piral-fetch')
ESM-only; piral-fetch is purely ESM. No default export, named import is correct.
createFetchApi
import { createFetchApi } from 'piral-fetch'
import createFetchApi from 'piral-fetch'
Default import incorrect; must use named import.
createFetchApi
const { createFetchApi } = await import('piral-fetch')
const { createFetchApi } = require('piral-fetch')
In Node.js with CommonJS, use dynamic import instead of require().

Sets up piral-fetch plugin with a base URL and default headers, then uses the fetch API in a pilet.

import { createInstance } from 'piral-core'; import { createFetchApi } from 'piral-fetch'; const instance = createInstance({ plugins: [createFetchApi({ base: process.env.BASE_URL ?? 'https://api.example.com', default: { headers: { 'Content-Type': 'application/json', }, }, })], // other config }); // In a pilet: export function setup(piral: PiletApi) { piral.fetch('/items') .then(res => res.body) .then(data => console.log(data)); }
Debug
Known issues
gotchaResponse from piral-fetch's fetch is different from browser fetch: it returns { code, body } instead of Response object.
fix
Use res.code for status code, res.body for parsed JSON (automatically parsed). Do not use res.json().
affects: >=1.0.0
gotchaRelative URLs are resolved against the configured base URL. If base is not set, relative URLs may fail.
fix
Always configure a base URL in createFetchApi options, or use absolute URLs.
affects: >=1.0.0
gotchaAuthentication tokens are only automatically inserted for requests to the base URL. Requests to other origins won't get tokens.
fix
Ensure fetch calls target the configured base URL, or manually add auth headers for other URLs.
affects: >=1.0.0
breakingIn piral-fetch v1, fetch returns a Promise<FetchResponse<T>> with code and body. In older piral versions (pre-1.0), the return type may have been different.
fix
Check the response shape: use .code (number) and .body (parsed JSON).
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'piral-fetch'
Missing dependency or incorrect import path.
fix
Run 'npm install piral-fetch' and ensure the import is from 'piral-fetch' (not 'piral-fetch-plugin' or similar).
TypeError: (0 , piral_fetch.createFetchApi) is not a function
Using default import instead of named import.
fix
Change 'import createFetchApi from "piral-fetch"' to 'import { createFetchApi } from "piral-fetch"'.
Uncaught TypeError: res.json is not a function
Using browser fetch response method on piral-fetch response.
fix
piral-fetch returns { code, body } where body is already parsed. Use res.body directly instead of res.json().
Upgrade
Version history
1.11.0latest on npm
Audit
Dependencies
piral-corerequiredpeer dependency required for plugin integration
Agent activity
7 hits · last 30 days
node
6
Resources
piral-fetch — npm install piral-fetch · libregistry