Kind: Interface
Source: src/client/types.ts
Part of: Client
ClientResponse is the typed response returned by the client layer. It extends the standard response shape with status-aware ok values and format-aware body readers such as json() and text().
Properties
| Property | Type |
|---|---|
body | `ReadableStream |
bodyUsed | boolean |
ok | U extends SuccessStatusCode ? true : U extends Exclude<StatusCode, SuccessStatusCode> ? false : boolean |
redirected | boolean |
status | U |
statusText | string |
type | `'basic' |
headers | Headers |
url | string |
Diagram
mermaidgraph LR ClientResponse --> Metadata[status, statusText, url, headers] ClientResponse --> Body[body, bodyUsed] ClientResponse --> Status[ok derived from status] ClientResponse --> Readers[json, text, blob, formData, bytes, arrayBuffer] ClientResponse --> ResponseOps[clone, redirect] Readers --> Payload[Typed payload based on response format]
Usage
tstype User = {
id: string
name: string
}
async function handleUserResponse(
response: ClientResponse<User, SuccessStatusCode, 'json'>
) {
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`)
}
const user = await response.json()
console.log(response.url)
console.log(user.name)
}
AI Coding Instructions
- Preserve the inferred
ClientResponse<T, U, F>type from client route calls sostatus,ok, and body reader return types remain specific. - Check
response.okorresponse.statusbefore reading a successful payload. - Call
json()only for JSON response formats;text()has separate type behavior for text responses. - A body reader consumes the response body. Use
clone()before reading when the body must be read again. - Read response metadata from
headers,url,redirected, andstatusTextrather than reconstructing it from request state.
Was this page helpful?