M

fetch-to-ky

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

This codemod is designed to help you migrate your existing codebase from using the native fetch API to the more concise and convenient ky HTTP client library. By running this codemod, you can automatically update your code to leverage ky's features, such as simpler syntax for common use cases like JSON requests and responses.

Detailed Description

The codemod performs the following transformations:

  • Replaces fetch calls with ky methods (ky.get, ky.post, ky.put, ky.delete).
  • Simplifies request setup by using ky's built-in methods for JSON handling (.json()).
  • Removes manual error checking (!resp.ok), as ky automatically throws errors for non-2xx responses.
  • Streamlines the code by reducing boilerplate and improving readability.

Example

Before

ts

After

ts

This codemod streamlines your existing fetch functions by converting them to use ky, eliminating unnecessary code, and making your HTTP requests more readable and maintainable.

Ready to contribute?

Build your own codemod and share it with the community.