Private Readonly basePrivate cachePrivate errorPrivate inflightPrivate requestPrivate responsePrivate buildPrivate buildPrivate buildPrivate buildOptional params: Record<PropertyKey, any>Private executePrivate executeSSEPrivate executeOptional params: Record<PropertyKey, any>Private isPrivate joinPrivate normalizePrivate parsePrivate parseSSEStreamOptional data: unknownOptional data: unknownOptional data: unknownPrivate readPrivate removePrivate runPrivate runPrivate runCreate an SSE (Server-Sent Events) connection.
Uses Fetch API under the hood, so it supports:
const api = new Request('https://api.example.com')
// GET SSE (default)
const handle = api.sse('/events', {
onMessage: (event) => console.log(event.data),
onError: (err) => console.error(err),
})
// POST SSE with data
const handle = api.sse('/chat/completions', {
method: 'POST',
data: { prompt: 'Hello' },
onMessage: (event) => {
const parsed = JSON.parse(event.data)
console.log(parsed)
},
})
// Cancel the connection
handle.abort()
```n
HTTP client with interceptors, timeout, retry, cache, deduplication, and download progress.
Basic usage
Composable best practice
Prefer small focused instances over one instance with all interceptors: