v1.0.2Latest / April 2026
Fetch
Make HTTP requests using the standard Fetch API, fully compatible with browser and Node.js patterns.
Basic usage
const res = await fetch("https://api.example.com/data")
const text = await res.text()
JSON requests
const res = await fetch("https://api.example.com/data")
const data = await res.json()
Headers
Set request headers with the Headers object:
const headers = new Headers()
headers.set("Authorization", `Bearer ${token}`)
headers.set("Content-Type", "application/json")
const res = await fetch(url, { headers })
POST and PUT
Send request bodies with any HTTP method:
const res = await fetch("https://api.example.com/items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "example", count: 42 }),
})
const created = await res.json()
Streaming responses
Process large responses as streams:
const res = await fetch("https://api.example.com/large")
const reader = res.body?.getReader()
const decoder = new TextDecoder()
while (reader) {
const { done, value } = await reader.read()
if (done) break
process.stdout.write(decoder.decode(value))
}
AbortController
Cancel in-flight requests with AbortController:
const controller = new AbortController()
setTimeout(() => controller.abort(), 5000)
const res = await fetch("https://api.example.com/slow", {
signal: controller.signal,
})
Aborted requests throw a DOMException with name AbortError.