Utilização

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'));

Declaração do tipo

ts
type BodyInit = string | ArrayBuffer | ArrayBufferView | URLSearchParams;

Membros 1

NomeTipoObrigatórioDescrição
toString(() => string) | (() => string) | (() => string)SimReturns a string representation of a string. Returns a string representation of an object. application/x-www-form-urlencoded: spaces as +.
toString — assinaturas de método

Assinaturas

ts
(): string

Parâmetros

Sem parâmetros.

Devolve

string

Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.