global.Response
A fetch response, for checking its status and reading its body whole or as it streams in.
Utilisation
Measure an operation without relying on wall-clock changes.
Ce type est utilisé par global.fetch
// Measure an operation without relying on wall-clock changes.
const start = performance.now();
const response = await fetch('https://example.com/api/health');
console.log(response.status, performance.now() - start);Déclaration du type
interface Response {
readonly ok: boolean;
readonly status: number;
readonly statusText: string;
/** The URL that answered, after redirects. */
readonly url: string;
readonly headers: Headers;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
bytes(): Promise<Uint8Array>;
text(): Promise<string>;
json(): Promise<unknown>;
/**
* Kuito's streaming read, in place of the Streams API: `onChunk` gets
* the body piece by piece as it arrives; resolves when it ends.
*/
chunks(onChunk: (chunk: Uint8Array) => void): Promise<void>;
}Membres 11
| Nom | Type | Requis | Description |
|---|---|---|---|
oklecture seule | boolean | Oui | — |
statuslecture seule | number | Oui | — |
statusTextlecture seule | string | Oui | — |
urllecture seule | string | Oui | The URL that answered, after redirects. |
headerslecture seule | Headers | Oui | — |
bodyUsedlecture seule | boolean | Oui | — |
arrayBuffer | () => Promise<ArrayBuffer> | Oui | — |
bytes | () => Promise<Uint8Array> | Oui | — |
text | () => Promise<string> | Oui | — |
json | () => Promise<unknown> | Oui | — |
chunks | (onChunk: (chunk: Uint8Array) => void) => Promise<void> | Oui | Kuito's streaming read, in place of the Streams API: onChunk gets
the body piece by piece as it arrives; resolves when it ends. |
arrayBuffer — signatures de méthode
Signatures
(): Promise<ArrayBuffer>Paramètres
Aucun paramètre.
Retourne
Promise<ArrayBuffer>
bytes — signatures de méthode
Signatures
(): Promise<Uint8Array>Paramètres
Aucun paramètre.
Retourne
Promise<Uint8Array<ArrayBufferLike>>
text — signatures de méthode
Signatures
(): Promise<string>Paramètres
Aucun paramètre.
Retourne
Promise<string>
json — signatures de méthode
Signatures
(): Promise<unknown>Paramètres
Aucun paramètre.
Retourne
Promise<unknown>
chunks — signatures de méthode
Signatures
(onChunk: (chunk: Uint8Array) => void): Promise<void>Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
onChunk | (chunk: Uint8Array) => void | Oui | — |
Retourne
Promise<void>
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.