{"library":"popsicle","title":"Popsicle HTTP Client","description":"Popsicle is an advanced HTTP client library designed for both Node.js and browser environments, currently stable at version 12.1.2. It provides a fetch-like API, built upon the `Servie` request and response interfaces, offering a universal solution without requiring environment-specific configuration by default. Releases typically involve patch updates for bug fixes and dependency management, with major versions introducing significant architectural changes, such as the `Servie 4` migration in v12.0.0. Key differentiators include its modular middleware architecture, which allows for extensive customization, and its optimized bundles for different environments. Node.js environments benefit from built-in features like User-Agent handling, content encoding decoding, redirect following, and an in-memory cookie cache, while browser builds are lighter, focusing solely on the `XMLHttpRequest` transport layer. This design allows developers to compose functionality and create highly tailored HTTP clients.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install popsicle"],"cli":null},"imports":["import { fetch } from 'popsicle';","import { AbortController } from 'popsicle';","import { Request, Response, Headers } from 'popsicle';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { fetch, AbortController } from \"popsicle\";\n\nconst controller = new AbortController();\nconst signal = controller.signal;\n\n// Simulate aborting the request after 500ms\nsetTimeout(() => {\n  console.log('Aborting request...');\n  controller.abort();\n}, 500);\n\nasync function makeRequest() {\n  try {\n    // Replace with a valid API endpoint for testing\n    const res = await fetch(\"https://jsonplaceholder.typicode.com/todos/1\", { signal });\n    if (!res.ok) {\n      throw new Error(`HTTP error! Status: ${res.status}`);\n    }\n    const data = await res.json();\n    console.log(\"Response data:\", data);\n  } catch (error: any) {\n    if (signal.aborted) {\n      console.log(`Request was aborted: ${error.name}`);\n    } else {\n      console.error(`Request failed unexpectedly: ${error.message}`);\n    }\n  }\n}\n\nmakeRequest();","lang":"typescript","description":"Demonstrates making an HTTP GET request using `fetch` and gracefully handling request abortion via `AbortController`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}