Skip to content

Releases

3.0.9

Choose a tag to compare

@elbywan elbywan released this 19 Jun 06:56
32d5f68

3.0.9 (2026-06-19)

🎨 Code improvement(s)

  • Narrow AbortAddon controller() return type to AbortController (6a83061)

🐛 Bug fix(es)

  • Fix .fetchError catching user errors (9a8faad), closes #318

3.0.8

Choose a tag to compare

@elbywan elbywan released this 23 May 10:53
76821f8

3.0.8 (2026-05-23)

⚠️ Potential TypeScript breaking change

This may surface new typescript errors in existing code that previously compiled with overly narrow types. In practice, this means code that assumed the result was always Data may now need to handle additional catcher return values.

Although this can be a type-level breaking change, it is a correctness fix: the previous typings were incomplete and did not match actual runtime behavior.

👉 This change does not affect runtime behavior.


🐛 Bug fix(es)

  • Fix catcher return type inference (f78f32a), closes #313

wretch now reflects catcher callback return types in the final promise type.

For example, this is now inferred correctly:

const result = await wretch(url)
  .get()
  .notFound(() => "notFound" as const)
  .json<Data>()

And result is now typed as:

Data | "notFound"

Catchers with no return value are now reflected as undefined, and the same typing improvement also applies through .resolve() and deferred catchers configured with .defer().

// a slightly more exhaustive example
const result = await wretch("https://example.com")
  .catcher(404, () => "404" as const)
  .catcher([401, 403, 407], () => "401/403/407" as const)
  .catcherFallback(() => "fallback" as const)
  .defer(w => w.catcher(404, () => "deferred" as const))
  .get()
  .notFound(() => "notFound" as const)
  .internalError(() => "internalError" as const)
  .error("custom", () => "customError" as const)
  .fetchError(() => "Fetch error" as const)
  .json<{ data: unknown }>()

const expected:
  { data: unknown }
  | "404"
  | "401/403/407"
  | "fallback"
  | "notFound"
  | "internalError"
  | "customError"
  | "Fetch error"
  | "deferred" = result

⬆️ Version update(s)

✅ Test improvement(s)

  • Properly typecheck tests (5af0e78)

3.0.7

Choose a tag to compare

@elbywan elbywan released this 07 Mar 06:59
0b90bc4

3.0.7 (2026-03-07)

🏭 New feature(s)

  • Allow multiple error ids on catchers (dc93190)
// Previously:
const api = wretch("https://api.example.com")
  .catcher(401, err => redirect("/login"))
  .catcher(403, err => redirect("/login"))
  .catcher(407, err => redirect("/login"))

// Now we can write:
const api = wretch("https://api.example.com")
  .catcher([401, 403, 407], err => redirect("/login"))

⬆️ Version update(s)

  • Bump fastify from 5.6.1 to 5.7.3 (153cae9)
  • Bump lodash from 4.17.21 to 4.17.23 (2355d02)
  • Bump qs from 6.14.0 to 6.14.2 (02ca86e)
  • Upgrade dependencies (f677f28)

3.0.6

Choose a tag to compare

@elbywan elbywan released this 12 Dec 19:42
c249220

3.0.6 (2025-12-12)

🐛 Bug fix(es)

  • Add Self to return type (e5582d6)
import wretch from "wretch";
import AbortAddon from "wretch/addons/abort";

const base = wretch()
  .addon(AbortAddon())
  .catcher(404, (error) => { throw error; });

// Previously: ❌ TypeScript error: Property 'signal' does not exist
// Now: 🟢
base.signal(new AbortController()).get("/test");
  • Widen catcherFallback error type (d0a3fbe), closes #290
import wretch from "wretch";

class ApiError extends Error {
  constructor(public status: number, message: string) {
    super(message);
  }
}

const api = wretch()
  .customError(async (error) => {
    return new ApiError(error.status, error.message);
  })
  .catcherFallback((error) => {
    // Previously 🔴
    // Error was typed as "ApiError"
    // But if you block the URL in Chrome DevTools (or network is down):
    // `error` is actually `TypeError: Failed to fetch`
    //
    // Now: 🟢
    // error is properly typed as "unknown" 
    console.log(error); 

   
  });

✅ Test improvement(s)

  • Add core snippet testing infrastructure (fcea6f7)
  • Add directive system for snippet test control (106e0d6)
  • Add execution engine and test orchestration (28f60a1)
  • Add extensible plugin system with examples (262a40d)
  • Integrate snippet testing framework and document usage (9cdeb4c)

3.0.5

Choose a tag to compare

@elbywan elbywan released this 27 Nov 08:06
c381be2

🎨 Code improvement(s)

  • Add progress option to customize the upload body size computation (2cd547f)
import ProgressAddon from "wretch/addons/progress"

wretch("https://example.com/upload")
  .addon(ProgressAddon({
    // getUploadTotal allows you to customize the total size of the upload
    getUploadTotal(url, opts) {
      // Return the total size of the upload in bytes, or 0 if undetermined
    },
  }))
  .get()
  .progress((loaded, total) => console.log(`${(loaded / total * 100).toFixed(0)}%`))

3.0.4

Choose a tag to compare

@elbywan elbywan released this 26 Nov 21:54
6077eb6

3.0.4 (2025-11-26)

🐛 Bug fix(es)

  • Improve body size computation when tracking upload progress (bfae158), closes #284
import wretch from "wretch"
import FormDataAddon from "wretch/addons/formData"
import ProgressAddon from "wretch/addons/progress"

const testString = Array(1_000).fill("This is a test string.")
const file = new File(testString, "test.txt", { type: "text/plain" })

wretch("https://httpbingo.org/post")
  .addon([ProgressAddon(), FormDataAddon])
  .formData({
    "textfile": file,
  })
  .onUpload((loaded, total) => {
    console.log(`Uploaded ${loaded} of ${total}`)
  })
  .post()
  .res(res => console.log(res.status))
  .catch(console.error)
# "total" is now correctly inferred:
Uploaded 0 of 22174
Uploaded 134 of 22174
Uploaded 156 of 22174
Uploaded 178 of 22174
Uploaded 200 of 22174
Uploaded 222 of 22174
# (…)
Uploaded 22090 of 22174
Uploaded 22112 of 22174
Uploaded 22134 of 22174
Uploaded 22136 of 22174
Uploaded 22174 of 22174
200

⬆️ Version update(s)

3.0.3

Choose a tag to compare

@elbywan elbywan released this 10 Nov 10:52
77a2d94

3.0.3 (2025-11-10)

🐛 Bug fix(es)

  • Use body size when available to compute upload total bytes (27c0443), closes #278
import wretch from "wretch"
import ProgressAddon from "wretch/addons/progress"

const testString = Array(50_000).fill("This is a test string.")
const file = new File(testString, "test.txt", { type: "text/plain" })

wretch("https://httpbin.org/post")
  .addon(ProgressAddon())
  .content("text/plain")
  .body(file)
  .onUpload((loaded, total) => {
    console.log(`Uploaded ${loaded} of ${total}`)
  })
  .post()
  .res(res => console.log(res.status))
  .catch(console.error)
Uploaded 0 of 1100000
Uploaded 589824 of 1100000
Uploaded 1100000 of 1100000

✅ Test improvement(s)

  • Migrate documentation examples from httpbun.org to htt (df84f73)

3.0.2

Choose a tag to compare

@elbywan elbywan released this 24 Oct 07:04
1680ef7

3.0.2 (2025-10-24)

🐛 Bug fix(es)

  • Clone the body before assigning to WretchError message (5379037), closes #277
try {
  // ..blah
} catch (err: unknown)
  if (err instanceof WretchError)
    // Should now work fine, used to crash with an error of type: "body has already been read"
    console.log(await err.response.json());
  }
}

3.0.1

Choose a tag to compare

@elbywan elbywan released this 21 Oct 21:54
66c0f09

3.0.1 (2025-10-21)

🐛 Bug fix(es)

  • Fix malformed package.json key (ddf3b4c)

📝 Documentation update(s)

  • Fix typescript API links (831598a)

3.0.0

Choose a tag to compare

@elbywan elbywan released this 19 Oct 18:00
5528b73

This major version represents a significant evolution of the library.

After extensive development, v3 delivers a smaller, faster, and more powerful fetch wrapper with improved type safety, smarter defaults, and exciting new features.

✨ What's New

🚀 Embracing Modern JavaScript

Wretch v3 now requires Node.js 22 or higher, allowing us to fully embrace the native Web APIs that are now built into the runtime. This means zero polyfill overhead - fetch, FormData, URLSearchParams, AbortController, and the Performance API are all used directly from Node.js.

The result? A significantly smaller bundle size and better performance thanks to highly optimized native implementations.

🎯 Better Error Handling with .customError()

Say goodbye to .errorType() and hello to the new .customError() method! This new helper function provides full TypeScript support for custom error properties, giving you complete control over error parsing.

Instead of being limited to predefined error types, you can now transform and parse errors exactly how you need them:

interface ApiError {
  code: number
  message: string
  details?: string
}

const api = wretch("https://api.example.com")
  .customError<ApiError>(async (error, response) => {
    return { ...error, json: await response.json() }
  })

api.get("/users")
  .badRequest(error => {
    console.log(error.json.message) // Fully typed!
  })
  .json()

🔄 Smarter Retry Defaults

The retry middleware now skips retrying 4xx client errors and focuses only on 5xx server errors and network failures.

This aligns perfectly with HTTP semantics - client errors like bad requests or authentication issues typically won't be fixed by retrying, while server errors and network issues are often transient:

import { retry } from "wretch/middlewares"

// Only retries 5xx and network errors, skips 4xx
wretch()
  .middlewares([retry()])
  .get("/api/data")
  .json()

Of course, you can still customize this behavior if needed using the until option.

📤 Upload Progress Monitoring

The Progress addon now lets you track upload progress in real-time:

import ProgressAddon from "wretch/addons/progress"
import FormDataAddon from "wretch/addons/formData"

await wretch("https://api.example.com/upload")
  .addon([ProgressAddon(), FormDataAddon])
  .formData({ file: myFile })
  .onUpload((loaded, total) => {
    console.log(`Upload: ${(loaded / total * 100).toFixed(0)}%`)
  })
  .post()
  .json()

This works seamlessly in Node.js for both HTTP and HTTPS. Note that browser support varies - Chrome/Chromium requires HTTPS, and Firefox doesn't support request body streaming yet.

🎨 Multiple Addons at Once

Small quality-of-life improvement, you can now pass multiple addons in a single call making your setup cleaner:

import QueryStringAddon from "wretch/addons/queryString"
import FormDataAddon from "wretch/addons/formData"
import AbortAddon from "wretch/addons/abort"

const api = wretch("https://api.example.com")
  .addon([QueryStringAddon, FormDataAddon, AbortAddon()])

💎 Improved API Design

Several addon methods now use options objects instead of positional parameters. This makes the API more maintainable, easier to extend in the future, and more readable:

// Query strings with clear options
wretch("https://api.example.com")
  .addon(QueryStringAddon)
  .query({ search: "test" }, { replace: true })
  .query({ filter: undefined }, { omitUndefinedOrNullValues: true })

// FormData with recursive options
wretch("https://api.example.com")
  .addon(FormDataAddon)
  .formData(data, { recursive: true })

🔗 Converting to Native Fetch

Need to pass a Wretch request to code that expects a native fetch call? The new .toFetch() method converts a Wretch request chain into a standard fetch invocation:

const [url, options] = wretch("https://api.example.com")
  .headers({ "X-Custom": "header" })
  .toFetch()

// Now use with native fetch or other libraries
await fetch(url, options)

🧹 Simplified Architecture

Version 3 removes global configuration methods in favor of cleaner per-instance configuration. Methods like wretch.options(), wretch.errorType(), and wretch.polyfills() are gone - now you configure each instance explicitly.

// ❌ v2 - Global configuration (removed in v3)
import wretch from 'wretch'

wretch.options({ mode: 'cors' })
wretch.errorType('json')

const api1 = wretch('https://api1.example.com')
const api2 = wretch('https://api2.example.com')

// ✅ v3 - Share configuration through a base wretch instance
import wretch from 'wretch'

const baseApi = wretch()
  .options({ mode: 'cors' })
  .customError(async (error, response) => {
    return { ...error, json: await response.json() }
  })

const api1 = baseApi.url('https://api1.example.com')
const api2 = baseApi.url('https://api2.example.com')
const api3 = baseApi.url('https://api3.example.com')

🔧 Modernized Development Stack

Behind the scenes, Wretch v3 represents a complete modernization of the development infrastructure:

Rolldown for bundling - Migrated from Rollup to Rolldown, resulting in significantly faster build times and a more efficient development workflow.
Native Node.js testing - Replaced Jest with Node.js's built-in node:test runner. No more heavy test framework dependencies - just fast, native testing that works out of the box.
Documentation testing - All code snippets in the documentation are now automatically tested to ensure they actually work. No more outdated examples!
Security updates - Resolved all security vulnerabilities and upgraded all development dependencies to their latest versions. The project is now running on modern, secure tooling throughout.
Comprehensive cross-runtime testing - Test suite now runs across Node.js, Deno, Bun, and browsers (via Web Test Runner) to ensure Wretch works flawlessly everywhere.
Automated publishing - Added automated npm publishing workflow for smoother releases.

These internal improvements mean faster development, more reliable releases, and better confidence that everything works as documented.

📖 Migration Guide

Wretch v3 includes breaking changes, but they're all for good reasons! Here are the key changes you'll need to handle:

Node.js version: You'll need Node.js 22 or higher to use v3. If you need to support older versions, stick with Wretch v2.
Error handling: Replace .errorType() with .customError() for more flexible, type-safe error parsing.
Global configuration: Remove calls to static methods like wretch.options() and configure each instance instead.
Addon parameters: Some addon methods now use options objects - notably .query(), .formData(), and .setTimeout().

For complete migration instructions with examples for every breaking change, check out the detailed migration guide.

📦 Installation

Ready to upgrade?

npm install wretch@latest

Need to stay on Node.js < 22?

npm install wretch@^2

💝 Thank You

Special thanks to all the users who have provided feedback and feature requests over the years. Your input helped shape this release and make Wretch better for everyone!

Happy wretching! 🎊