
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
itty-fetcher
Advanced tools
Fetcher is an ultra-compact (~650 bytes) wrapper around native Fetch, designed purely to avoid boilerplate steps and shrink downstream code.
const newUser = await fetcher().post<NewUser, User>('/api/users', { name: 'Alice' })
const newUser = await fetch('/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Alice' })
}).then(response => {
if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`)
return response.json()
})
import { fetcher } from 'itty-fetcher' // ~650 bytes
let fetcher=(e,t)=>{let s="string"==typeof e?{base:e,...t}:e||{};return new Proxy(()=>{},{get:(e,t)=>(...e)=>(async(e,t,s,r=("string"==typeof s[0]?s.shift():""),a=("GET"!=e?s.shift():null),n={...t,...s.shift(),method:e},o=new Headers(t.headers),i="string"==typeof a,f=t.base??"")=>{r=new URL((r.includes("://")?r:(f.includes?.("://")?f:globalThis.location?.href+"/"+f)+(r?"/"+r:"")).replace(/\/+/g,"/"));for(let e in n.query||{})r.searchParams.append(e,n.query[e]);n.body=a,a&&0!=n.encode&&(n.body=i?a:JSON.stringify(a),i||o.set("content-type","application/json"));for(let[e,t]of new Headers(n.headers||[]))o.set(e,t);let p=await(n.fetch||fetch)(new Request(r,{...n,headers:o})),c=p.ok?void 0:Object.assign(new Error(p.statusText),{status:p.status,response:p});if(n.parse??"json")try{p=await p[n.parse??"json"](),c&&"json"==(n.parse??"json")&&(c={...c,...p})}catch(e){c||(c=Object.assign(new Error(e.message),{status:p.status,response:p}))}for(let e of n.after||[])p=await e(p)??p;if(n.array)return[c,c?void 0:p];if(c)throw c;return p})(t.toUpperCase(),s,e)})};
Note: This will lose TypeScript support, but is great for adding to your browser console (via script extensions, etc).
const items = await fetcher().get('https://example.com/api/items')
// or typed...
const items = await fetcher<MyCustomType[]>().get('https://example.com/api/items')
const api = fetcher('https://example.com', { // set a base url
headers: { 'x-api-key': 'my-secret-key' }, // add a header to all requests
after: [console.log], // and some response handlers/transforms
})
// to make api calls even sexier
const items = await api.get('/items')
// no need to encode/decode for JSON payloads
api.post('/items', { foo: 'bar' })
Like any itty.dev project, this is not a kitchen-sink library. If you need advanced features like automatic retries or complex request interception, consider a more full-featured library. This is for when you want native fetch behavior with dramatically less boilerplate.
âś… Perfect for:
❌ Consider alternatives for:
Built with ❤️ by Kevin Whitley and the Itty community.
FAQs
Fetch, without the boilerplate (and Typed).
We found that itty-fetcher demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.