--- title: Body slug: Web/API/Body tags: - API - BODY - Experimental - Fetch - Fetch API - Interface - NeedsTranslation - Reference - TopicStub - request translation_of: Web/API/Body ---
{{ APIRef("Fetch") }}

The Body {{glossary("mixin")}} of the Fetch API represents the body of the response/request, allowing you to declare what its content type is and how it should be handled.

Body is implemented by both {{domxref("Request")}} and {{domxref("Response")}}. This provides these objects with an associated body (a stream), a used flag (initially unset), and a MIME type (initially the empty byte sequence).

Properties

{{domxref("Body.body")}} {{readonlyInline}}
A simple getter used to expose a {{domxref("ReadableStream")}} of the body contents.
{{domxref("Body.bodyUsed")}} {{readonlyInline}}
A {{domxref("Boolean")}} that indicates whether the body has been read.

Methods

{{domxref("Body.arrayBuffer()")}}
Takes a {{domxref("Response")}} stream and reads it to completion. It returns a promise that resolves with an {{domxref("ArrayBuffer")}}.
{{domxref("Body.blob()")}}
Takes a {{domxref("Response")}} stream and reads it to completion. It returns a promise that resolves with a {{domxref("Blob")}}.
{{domxref("Body.formData()")}}
Takes a {{domxref("Response")}} stream and reads it to completion. It returns a promise that resolves with a {{domxref("FormData")}} object.
{{domxref("Body.json()")}}
Takes a {{domxref("Response")}} stream and reads it to completion. It returns a promise that resolves with the result of parsing the body text as {{jsxref("JSON")}}.
{{domxref("Body.text()")}}
Takes a {{domxref("Response")}} stream and reads it to completion. It returns a promise that resolves with a {{domxref("USVString")}} (text). The response is always decoded using UTF-8.

Examples

The example below uses a simple fetch call to grab an image and display it in an {{htmlelement("img")}} tag. You'll notice that since we are requesting an image, we need to run {{domxref("Body.blob","Body.blob()")}} ({{domxref("Response")}} implements body) to give the response its correct MIME type.

HTML Content

<img class="my-image" src="https://wikipedia.org/static/images/project-logos/frwiki-1.5x.png">

JS Content

var myImage = document.querySelector('.my-image');
fetch('https://upload.wikimedia.org/wikipedia/commons/7/77/Delete_key1.jpg')
	.then(res => res.blob())
	.then(res => {
		var objectURL = URL.createObjectURL(res);
		myImage.src = objectURL;
});

{{ EmbedLiveSample('Examples', '100%', '250px') }}

Specifications

Specification Status Comment
{{SpecName('Fetch','#body-mixin','Body')}} {{Spec2('Fetch')}}  

Browser compatibility

{{Compat("api.Body")}}

See also