Usage

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

Constructors

ts
(): TextEncoder

Parameters

No parameters.

Returns

TextEncoder

Properties and methods 4

NameTypeRequiredDescription
prototypereadonlyTextEncoderYes—
encodingreadonly"utf-8"Yes—
encode(text?: string) => Uint8ArrayYes—
encodeInto(text: string, into: Uint8Array) => { read: number; written: number;}Yes—
encode — method signatures

Signatures

ts
(text?: string): Uint8Array

Parameters

NameTypeRequiredDescription
textstringNo—

Returns

Uint8Array<ArrayBufferLike>

encodeInto — method signatures

Signatures

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

Parameters

NameTypeRequiredDescription
textstringYes—
intoUint8Array<ArrayBufferLike>Yes—

Returns

{ read: number; written: number;}

Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.