Utilisation

Send text, form fields or bytes with fetch.

tsx
// Send text, form fields or bytes with fetch.
async function post(url: string, body: BodyInit) {
  const response = await fetch(url, { method: 'POST', body });

  if (!response.ok) throw new Error(`${url} answered ${response.status}`);
}

await post('https://api.example.com/login', new URLSearchParams({ user: 'ana', remember: '1' }));
await post('https://api.example.com/notes', 'Plain text, sent as UTF-8');
await post('https://api.example.com/upload', new TextEncoder().encode('bytes'));

Constructeurs

ts
(): TextEncoder

Paramètres

Aucun paramètre.

Retourne

TextEncoder

Propriétés et méthodes 4

NomTypeRequisDescription
prototypelecture seuleTextEncoderOui—
encodinglecture seule"utf-8"Oui—
encode(text?: string) => Uint8ArrayOui—
encodeInto(text: string, into: Uint8Array) => { read: number; written: number;}Oui—
encode — signatures de méthode

Signatures

ts
(text?: string): Uint8Array

Paramètres

NomTypeRequisDescription
textstringNon—

Retourne

Uint8Array<ArrayBufferLike>

encodeInto — signatures de méthode

Signatures

ts
(text: string, into: Uint8Array): { read: number; written: number; }

Paramètres

NomTypeRequisDescription
textstringOui—
intoUint8Array<ArrayBufferLike>Oui—

Retourne

{ read: number; written: number;}

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.