{"id":49764,"library":"wretch","title":"wretch","description":"A tiny (~1.8KB g-zipped) wrapper around the Fetch API with an intuitive, chainable syntax. v3.0.8 (latest) is actively maintained and supports modern browsers, Node.js 22+, Deno, and Bun. Key differentiators: immutable API (cloning for reuse), automatic JSON serialization/deserialization, error handling via status-specific handlers (notFound, internalError, etc.), addon/middleware system, and full TypeScript types. Compared to alternatives like ky or axios, wretch is lighter and focuses on a minimal, functional style.","status":"active","version":"3.0.8","language":"javascript","source_language":"en","source_url":"https://github.com/elbywan/wretch","tags":["javascript","wretch","fetch","ajax","request","typescript"],"install":[{"cmd":"npm install wretch","lang":"bash","label":"npm"},{"cmd":"yarn add wretch","lang":"bash","label":"yarn"},{"cmd":"pnpm add wretch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v3; requires Node with { type: 'module' } or bundler.","wrong":"const wretch = require('wretch')","symbol":"default export","correct":"import wretch from 'wretch'"},{"note":"Named export for error handling; also ESM-only.","wrong":"const { WretchError } = require('wretch')","symbol":"WretchError","correct":"import { WretchError } from 'wretch'"},{"note":"TypeScript users should import the Wretch type explicitly for type annotations.","wrong":"","symbol":"Wretch (TypeScript type)","correct":"import type { Wretch } from 'wretch'"},{"note":"Available as named type exports for custom addons/middlewares.","wrong":"","symbol":"WretchAddon / Middleware types","correct":"import type { WretchAddon, WretchMiddleware } from 'wretch'"}],"quickstart":{"code":"import wretch from 'wretch'\n\nconst api = wretch('https://jsonplaceholder.typicode.com')\n  .options({ mode: 'cors' })\n\n// GET with automatic JSON parsing\nconst post = await api.get('/posts/1').json()\nconsole.log(post.title)\n\n// POST with automatic serialization\nconst created = await api\n  .post({ title: 'New Post', body: 'Content', userId: 1 }, '/posts')\n  .json()\n\n// Error handling with status shortcuts\nawait api\n  .get('/posts/999')\n  .notFound(() => console.log('Post not found!'))\n  .json()\n\n// Different response types\nconst text = await api.get('/posts/1').text()\nconst response = await api.get('/posts/1').res()\nconst blob = await api.get('/photos/1').blob()","lang":"typescript","description":"Basic usage of wretch: create an API client, perform GET/POST requests, handle errors with status-specific callbacks, and retrieve responses as JSON, text, raw Response, or Blob."},"warnings":[{"fix":"Use import syntax (import wretch from 'wretch') and ensure your project is ESM (e.g., package.json type: module).","message":"wretch v3 dropped CommonJS support and is ESM-only.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace new wretch(...) with wretch(...) (no new keyword).","message":"Default export is now a factory function, not a class constructor.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use error.status and error.message instead of error.statusCode and error.text.","message":"WretchError renamed properties: 'status' was 'statusCode', 'message' was 'text'.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use status-specific handlers (.notFound(), .internalError(), etc.) instead of .error() if you need fine-grained control.","message":"The .error() handler catches any non-OK response (status >= 400), not just network errors.","severity":"gotcha","affected_versions":"*"},{"fix":"Replace .body() with .content() for setting request body content types.","message":"wretch().body() is deprecated in v3. Use wretch().content() instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Upgrade Node.js to 22+ or use wretch v2 (but v2 is in maintenance mode).","message":"wretch v3 requires Node.js >=22; older Node versions will fail.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'1.8':4 '22':29 'activ':22 'addon/middleware':53 'ajax':79 'altern':61 'api':13,36 'around':10 'automat':40 'axio':65 'browser':27 'bun':32 'chainabl':17 'clone':37 'compar':59 'deno':30 'differenti':34 'error':43 'etc':52 'fetch':12,78 'focus':70 'full':56 'function':74 'g':7 'g-zip':6 'handl':44 'handler':49 'immut':35 'internalerror':51 'intuit':16 'javascript':76 'json':41 'kb':5 'key':33 'ky':63 'latest':20 'lighter':68 'like':62 'maintain':23 'minim':73 'modern':26 'node.js':28 'notfound':50 'request':80 'reus':39 'serialization/deserialization':42 'specif':48 'status':47 'status-specif':46 'style':75 'support':25 'syntax':18 'system':54 'tini':3 'type':58 'typescript':57,81 'v3.0.8':19 'via':45 'wrapper':9 'wretch':1,66,77 'zip':8","created_at":"2026-06-07T17:03:29.228246+00:00","updated_at":"2026-06-07T17:03:29.228246+00:00","problems":[{"fix":"Switch your project to ESM (add \"type\": \"module\" to package.json) or use dynamic import() instead of require().","cause":"wretch v3 is ESM-only, but you're using require() in a CommonJS context.","error":"ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/wretch/dist/index.js from /path/to/your/file.js not supported."},{"fix":"Remove the new keyword: const api = wretch('https://example.com').","cause":"Using new wretch() which is invalid in v3 (wretch is a factory function).","error":"TypeError: wretch is not a constructor"},{"fix":"Replace .body(contentType) with .content(contentType).","cause":".body() was removed in v3; use .content() instead.","error":"TypeError: wretch(...).body is not a function"},{"fix":"Use error.status instead of error.statusCode.","cause":"WretchError property renamed in v3 from statusCode to status.","error":"Property 'statusCode' does not exist on type 'WretchError'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://elbywan.github.io/wretch","github":"https://github.com/elbywan/wretch","docs":null,"changelog":null,"pypi":null,"npm":"wretch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}