Skip to content

docs: document createFetch custom fetch option#603

Open
poetryofcode wants to merge 1 commit into
unjs:mainfrom
poetryofcode:docs/document-createFetch-custom-fetch-option
Open

docs: document createFetch custom fetch option#603
poetryofcode wants to merge 1 commit into
unjs:mainfrom
poetryofcode:docs/document-createFetch-custom-fetch-option

Conversation

@poetryofcode

@poetryofcode poetryofcode commented Jun 29, 2026

Copy link
Copy Markdown

Summary

Fixes #533

The createFetch function accepts a fetch option in CreateFetchOptions that lets you provide a custom fetch implementation. This is useful for Node.js-compatible fetch (e.g. undici), service worker fetch, or test mocks — but it was completely undocumented in the README.

Changes

  • README.md: Added a new "🔧 Using a custom fetch implementation" section after "Create fetch with default options", showing how to use createFetch({ fetch: customImpl }) with a basic example and a practical undici example.

Test plan

  • README renders correctly on GitHub and npmjs.com

Summary by CodeRabbit

  • Documentation
    • Added guidance for using a custom fetch implementation when creating an ofetch instance.
    • Included examples for passing a custom fetch function and using undici’s fetch in Node.js.
    • Expanded the setup docs with this new option alongside the default configuration example.

The `createFetch` function accepts a `fetch` option in `CreateFetchOptions`
that allows passing a custom fetch implementation. This is useful for
providing a Node.js-compatible fetch (e.g. undici), a service worker's
fetch, or a test mock — but was not documented in the README.

Closes unjs#533

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 25d4d2d3-9d26-4410-90c3-79ed29745c8a

📥 Commits

Reviewing files that changed from the base of the PR and between 9102908 and 8fa6e11.

📒 Files selected for processing (1)
  • README.md

📝 Walkthrough

Walkthrough

A new "Using a custom fetch implementation" subsection is added to README.md, documenting createFetch({ fetch }) with examples for a generic custom fetch function and undici's fetch in Node.js.

Changes

Custom fetch documentation

Layer / File(s) Summary
createFetch custom fetch section
README.md
Adds a subsection with two code examples showing how to wire ofetch to a caller-provided fetch implementation, including undici usage for Node.js.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through Node.js land,
With undici fetch close at hand.
"No docs?" it cried, then wrote them clear,
createFetch({ fetch }) — now have no fear!
The README blooms, the gap is filled. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the doc update for documenting the custom fetch option.
Linked Issues check ✅ Passed The README now documents createFetch({ fetch }) as requested in issue #533, including example usages.
Out of Scope Changes check ✅ Passed The changes are limited to README documentation and stay within the issue's scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to pass in custom fetch fn is not documented

1 participant