Registry / testing / a-fetch

a-fetch

JSON →
library1.3.3jsnpmunverified

a-fetch (v1.3.3) allows you to name your API routes and request them by route name, supporting GET, POST, PUT, and DELETE. It provides a clean and structured way to manage API calls, especially in React projects. The package is actively maintained with moderate release cadence. It differentiates by offering a simple naming convention over manual fetch calls, reducing boilerplate.

npm install a-fetch
INSTALL
IMPORT
SIG · A-FETCH
A
a-fetch
testingjavascriptv1.3.3
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.

Api
import Api from 'a-fetch'
const { Api } = require('a-fetch')
Default export is a class; not a named export.
request
import { request } from 'a-fetch'
import request from 'a-fetch'
request is a named export, not default.
create
import { create } from 'a-fetch'
import create from 'a-fetch'
create is a named export, not default.

Shows how to create an Api instance with named routes and perform a GET request.

import Api from 'a-fetch'; const api = new Api({ baseURL: process.env.API_BASE_URL ?? 'https://jsonplaceholder.typicode.com', routes: { posts: { get: { method: 'GET', path: '/posts' }, create: { method: 'POST', path: '/posts' } } } }); async function fetchPosts() { const { data } = await api.posts.get(); console.log(data); } fetchPosts();
Debug
Known issues
gotchaRoute names must match the property used to call them; typos cause silent failures.
fix
Use TypeScript or double-check route names in the config.
affects: >=1.0.0
gotchaThe default export Api is a class and must be instantiated with 'new'.
fix
Always use 'new Api(...)'.
affects: >=1.0.0
breakingVersion 1.2 changed the method names from 'fetch' to 'get', 'create', etc.
fix
Update method calls to use the new names.
affects: >=1.2.0 <1.2.0
Errors
Common errors & fixes
Uncaught TypeError: api.posts.get is not a function
Route 'posts' not configured or 'get' method not defined in routes.
fix
Check that the route configuration includes a 'posts' object with a 'get' property.
Cannot read properties of undefined (reading 'data')
The response object might not contain 'data' or the request failed.
fix
Use try-catch and log the full response to inspect structure.
Upgrade
Version history
1.3.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
54 hits · last 30 days
node
44
OpenAI (training)
1
Resources
a-fetch — npm install a-fetch · libregistry