es-fetch-api
Use this skill when the user's input contains keywords like "es-fetch-api", "fetch wrapper", "http client", "api request", "/use fetch" or when they need to make HTTP requests in a JavaScript/TypeScript project. This skill provides installation guides, usage examples, and best practices.
Best use case
es-fetch-api is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Use this skill when the user's input contains keywords like "es-fetch-api", "fetch wrapper", "http client", "api request", "/use fetch" or when they need to make HTTP requests in a JavaScript/TypeScript project. This skill provides installation guides, usage examples, and best practices.
Teams using es-fetch-api should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/es-fetch-api/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How es-fetch-api Compares
| Feature / Agent | es-fetch-api | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Use this skill when the user's input contains keywords like "es-fetch-api", "fetch wrapper", "http client", "api request", "/use fetch" or when they need to make HTTP requests in a JavaScript/TypeScript project. This skill provides installation guides, usage examples, and best practices.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# es-fetch-api
This skill provides instructions and examples for using the `es-fetch-api` library.
## Installation
To use `es-fetch-api` in a project, first install it via npm:
```bash
npm install es-fetch-api
```
## Overview
`es-fetch-api` is a lightweight, middleware-based wrapper around the native `fetch` API. It allows you to compose requests using a chain of middlewares for handling query parameters, request bodies, headers, and more.
## Usage
### 1. Initialize API Client
Use `getApi` to create an API client instance with a base URL.
```javascript
import { getApi } from 'es-fetch-api';
const api = getApi('https://api.example.com');
```
### 2. Making Requests
The `api` function takes an endpoint path and a variable number of middlewares.
#### GET Request with Query Parameters
Use the `query` middleware to handle URL search parameters.
```javascript
import { query } from 'es-fetch-api/middlewares/query.js';
// GET https://api.example.com/users?page=1&limit=10
await api('/users', query({ page: 1, limit: 10 }));
```
#### POST JSON Request
Use the `json` middleware to send a JSON body. This automatically sets the `Content-Type: application/json` header.
```javascript
import { json } from 'es-fetch-api/middlewares/body.js';
// POST https://api.example.com/users
await api('/users', json({ name: 'Alice', age: 30 }));
```
#### POST Form Data
Use the `form` middleware to send `application/x-www-form-urlencoded` data.
```javascript
import { form } from 'es-fetch-api/middlewares/body.js';
// POST https://api.example.com/login
await api('/login', form({ username: 'user', password: 'pass' }));
```
#### File Upload (Multipart)
Use the `file` middleware to upload files. This uses `FormData` internally.
```javascript
import { file } from 'es-fetch-api/middlewares/body.js';
// POST https://api.example.com/upload
// Assuming `avatarBlob` is a Blob or File object
await api('/upload', file('avatar', avatarBlob, 'avatar.png'));
```
#### Custom Headers
Use the `header` middleware to set request headers.
```javascript
import { header } from 'es-fetch-api/middlewares/header.js';
await api('/protected', header({ 'Authorization': 'Bearer token' }));
```
#### Explicit HTTP Methods
By default, the method is inferred or defaults to GET. You can enforce a method using method middlewares.
```javascript
import { DELETE, PUT } from 'es-fetch-api/middlewares/methods.js';
// DELETE https://api.example.com/users/123
await api('/users/123', DELETE);
// PUT https://api.example.com/users/123
await api('/users/123', PUT, json({ name: 'Bob' }));
```
#### Abortable Requests
Use the `abortable` middleware with an `AbortController` to cancel requests.
```javascript
import { abortable } from 'es-fetch-api/middlewares/abortable.js';
const controller = new AbortController();
// Request will be aborted when controller.abort() is called
await api('/long-task', abortable(controller));
// To cancel:
// controller.abort();
```
## Best Practices
### 1. Use Unified Base URL Handling
Avoid passing absolute URLs for every request. Instead, define a helper to retrieve the base URL dynamically.
```javascript
export const getBaseUrl = () => window.appSettings?.api.backend ?? import.meta.env.VITE_APP_API
```
### 2. Use a Unified API Invocation Method
Avoid calling `getApi` in every function. Create a centralized `invokeApi` function.
```javascript
export const invokeApi = (...args) => {
const api = getApi(getBaseUrl())
return api(...args, useToken()); // Automatically inject token if needed
}
```
### 3. Centralize Response Handling
Create helper functions like `getData` and `getText` to handle response parsing centrally, rather than repeating `response.json()` or `response.text()` in every call.
```javascript
export const getData = async (...args) => {
const response = await invokeApi(...args)
return response?.json()
}
export const getText = async (...args) => {
const response = await invokeApi(...args)
return response.text()
}
```
### 4. Unified Authentication Handling
Use middleware for authentication instead of manually adding headers in every request.
```javascript
export const requireToken = () => async (ctx, next) => {
const token = await getToken() // your token retrieval logic
if (!token) return
// Header middleware or manual header setting can be done here if not handled by `useToken` logic above
// Or simply ensure `useToken` middleware is part of the chain as shown in invokeApi
return next()
}
// Example usage in invokeApi:
export const invokeApi = (...args) => {
const api = getApi(getBaseUrl())
return api(...args, requireToken());
}
```
### 5. Use Arrow Functions for Business Logic
Prefer concise arrow functions (lambdas) for defining business logic API methods.
```javascript
export const getExpenseTypes = (companyId) =>
getData('expense-types', query({ companyId }));
```
### Other Tips
- Always use the provided middlewares (`json`, `query`, etc.) instead of manually constructing bodies or query strings.
- Import only the middlewares you need to keep the bundle size small.Related Skills
browser-fetch
Delegate browser automation to a lightweight subagent (Haiku) to reduce context consumption. Also provides web clipping (HTML→Markdown) via clipper.
native-data-fetching
Use when implementing or debugging ANY network request, API call, or data fetching. Covers fetch API, axios, React Query, SWR, error handling, caching strategies, offline support.
langsmith-fetch
Debug LangChain and LangGraph agents by fetching execution traces from LangSmith Studio. Use when debugging agent behavior, investigating errors, analyzing tool calls, checking memory operations, or examining agent performance. Automatically fetches recent traces and analyzes execution patterns. Requires langsmith-fetch CLI installed.
economic-calendar-fetcher
Fetch upcoming economic events and data releases using FMP API. Retrieve scheduled central bank decisions, employment reports, inflation data, GDP releases, and other market-moving economic indicators for specified date ranges (default: next 7 days). Output chronological markdown reports with impact assessment.
data-fetching
Data fetching architecture guide using Service layer + Zustand Store + SWR. Use when implementing data fetching, creating services, working with store hooks, or migrating from useEffect. Triggers on data loading, API calls, service creation, or store data fetching tasks.
data-fetching-patterns
Explains data fetching strategies including fetch on render, fetch then render, render as you fetch, and server-side data fetching. Use when implementing data loading, optimizing loading performance, or choosing between client and server data fetching.
fetch-rules
Fetch and apply Cursor-style workspace rules supporting all rule formats (.cursor/rules/*.md, *.mdc, AGENTS.md, and legacy .cursorrules).
bgo
Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.
fastapi-python-expert
Use this agent when you need to design, implement, or optimize FastAPI backend applications. This includes API endpoint creation, database integration, authentication/authorization implementation, cloud deployment strategies, business logic architecture, performance optimization, and following FastAPI best practices.
fastapi-project
Scaffold and evolve FastAPI projects with uv-based tooling, structured settings, and production-ready observability, resilience, availability, and security patterns aligned with python.instructions.md.
fastapi-pro
Build high-performance async APIs with FastAPI, SQLAlchemy 2.0, and Pydantic V2. Master microservices, WebSockets, and modern Python async patterns. Use PROACTIVELY for FastAPI development, async optimization, or API architecture.
fastapi-patterns
FastAPI patterns with Pydantic, async operations, and dependency injection