es-fetch-api

Wrap native fetch with middlewares for GET and POST requests.

16|Updated Feb 4, 2022
One-click install
npx skills add https://github.com/lchrennew/es-fetch-api --skill es-fetch-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: es-fetch-api
Source: https://github.com/lchrennew/es-fetch-api/tree/main
Command: npx skills add https://github.com/lchrennew/es-fetch-api --skill es-fetch-api

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill reduces repetitive boilerplate when making HTTP requests in JavaScript/TypeScript by wrapping the native fetch API with a middleware-driven API.

Core Features & Use Cases

  • Middleware-based request composition: query, json, form, header, and abortable middlewares to build requests in a readable, declarative style.
  • Client for Node and browser: works in both environments through a base URL with getApi and endpoint chaining.
  • Use Case: Initialize an API client with a base URL and perform GET with query params or POST with JSON bodies in a clean, maintainable way.

Quick Start

Install the library with npm install es-fetch-api, then initialize:

  • const api = getApi('https://api.example.com');
  • await api('/users', query({ page: 1 }));
  • await api('/login', POST, json({ username, password }));

Frequently Asked Questions about es-fetch-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce repetitive fetch API boilerplate in JavaScript and TypeScript?

To reduce repetitive fetch API boilerplate in JavaScript, use a middleware-driven wrapper around the native fetch API. It allows you to compose requests declaratively by chaining middlewares for query parameters, JSON bodies, and headers, eliminating redundant setup code.

How do I add query parameters and JSON bodies to HTTP requests using middleware?

You add query parameters and JSON bodies to HTTP requests by applying specific middlewares like query, json, or form to your fetch call. This declarative composition injects the necessary formatting into the request without manual header serialization or URL string concatenation.

Does this fetch API wrapper work in both Node and browser environments?

Yes, this fetch API wrapper works in both Node and browser environments. You initialize a client with a base URL using getApi and chain endpoints, allowing you to execute HTTP requests seamlessly across different JavaScript runtime platforms.

What is the best way to structure an API client for base URLs and endpoint chaining?

The best way to structure an API client for base URLs and endpoint chaining is to initialize it with a base URL function like getApi. You then append specific endpoints and apply middlewares, creating a maintainable and reusable HTTP request architecture across your project.

Can I make abortable HTTP requests with a fetch middleware wrapper?

Yes, you can make abortable HTTP requests with a fetch middleware wrapper by utilizing the abortable middleware. This integrates request cancellation directly into the chainable middleware system, allowing you to cleanly terminate ongoing fetch calls when needed.