resolves with a [ ` FormData ` ](/en-
US/docs/Web/API/FormData) representation of the request body.

[ ` Request.json() ` ](/en-US/docs/Web/API/Request/json)

    

Returns a promise that resolves with the result of parsing the request body as
[ ` JSON ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) .

[ ` Request.text() ` ](/en-US/docs/Web/API/Request/text)

    

Returns a promise that resolves with a text representation of the request
body.

**Note:** The request body functions can be run only once; subsequent calls
will reject with TypeError showing that the body stream has already used.

##  Examples

In the following snippet, we create a new request using the ` Request() `
constructor (for an image file in the same directory as the script), then
return some property values of the request:

js

    
    
    const request = new Request("https://www.mozilla.org/favicon.ico");
    
    const url = request.url;
    const method = request.method;
    const credentials = request.credentials;
    

You could then fetch this request by passing the ` Request ` object in as a
parameter to a [ ` fetch() ` ](/en-US/docs/Web/API/fetch) call, for example:

js

    
    
    fetch(request)
      .then((response) => response.blob())
      .then((blob) => {
        image.src = URL.createObjectURL(blob);
      });
    

In the following snippet, we create a new request using the ` Request() `
constructor with some initial data and body content for an API request which
need a body payload:

js

    
    
    const request = new Request("https://example.com", {
      method: "POST",
      body: '{"foo": "bar"}',
    });
    
    const url = request.url;
    const method = request.method;
    const credentials = request.credentials;
    const bodyUsed = request.bodyUsed;
    

**Note:** The body can only be a [ ` Blob ` ](/en-US/docs/Web/API/Blob) , an [
` ArrayBuffer ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) , a [ `
TypedArray ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
, a [ ` DataView ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/DataView) , a [ ` FormData `
](/en-US/docs/Web/API/FormData) , a [ ` URLSearchParams ` ](/en-
US/docs/Web/API/URLSearchParams) , a [ ` ReadableStream ` ](/en-
US/docs/Web/API/ReadableStream) , or a [ ` String ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String) object, as well as a
string literal, so for adding a JSON object to the payload you need to
stringify that object.

You could then fetch this API request by passing the ` Request ` object in as
a parameter to a [ ` fetch() ` ](/en-US/docs/Web/API/fetch) call, for example
and get the response:

js

    
    
    fetch(request)
      .then((response) => {
        if (response.status === 200) {
          return response.json();
        } else {
          throw new Error("Something went wrong on API server!");
        }
      })
      .then((response) => {
        console.debug(response);
        // â¦
      })
      .catch((error) => {
        console.error(error);
      });
    

##  Specifications

Specification  
---  
[ Fetch Standard  
#  request-class  ](https://fetch.spec.whatwg.org/#request-class)  
  
##  Browser compatibility

BCD tables only load in the browser  with JavaScript enabled. Enable
JavaScript to view data.

##  See also

  * [ ServiceWorker API ](/en-US/docs/Web/API/Service_Worker_API)
  * [ HTTP access control (CORS) ](/en-US/docs/Web/HTTP/CORS)
  * [ HTTP ](/en-US/docs/Web/HTTP)

##  Help improve MDN

Was this page helpful to you?

Yes  No

[ Learn how to contribute
](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you
to our contribution guidelines on GitHub.") .

This page was last modified on  Sep 16, 2023  by  [ MDN contributors ](/en-
US/docs/Web/API/Request/contributors.txt) .

[ View this page on GitHub
](https://github.com/mdn/content/blob/main/files/en-
us/web/api/request/index.md?plain=1 "Folder: en-us/web/api/r