Firefox Tomorrow

web api instance method

Request: text() method

View on MDN ↗

Available in workers

The text() method of the Request interface reads the request body and returns it as a promise that resolves with a String. The response is always decoded using UTF-8.

Syntax

text()

Parameters

None.

Return value

A Promise that resolves with a String.

Exceptions

Examples

const text = "Hello world";

const request = new Request("/myEndpoint", {
  method: "POST",
  body: text,
});

request.text().then((text) => {
  // do something with the text sent in the request
});

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also