Migration Guides
Migrating from Native fetch
Before (Raw Fetch):
tsconst params = new URLSearchParams({ type: 'admin' }); const res = await fetch(`/api/users?\${params.toString()}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ active: true }) }); if (!res.ok) throw new Error("Status " + res.status); const data = await res.json();
After (BoltFetch):
tsconst res = await boltfetch.post('/api/users', { params: { type: 'admin' }, body: { active: true } }); if (!res.success) return; // handles non-2xx statuses automatically const data = res.data;
Migrating from Axios
Before (Axios):
tstry { const response = await axios.get('/api/data'); setData(response.data); } catch (error) { if (axios.isAxiosError(error)) { console.error(error.response?.data); } }
After (BoltFetch):
tsconst res = await boltfetch.get('/api/data'); if (res.success) { setData(res.data); } else { console.error(res.moreInfo); }