---
title: FastlyBody
summary: A low-level API for constructing and manipulating HTTP message bodies outside of the standard Fetch API.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/body/class.FastlyBody/
---

**Kind:** Class  
**Module:** [body](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/body/)  
**Package:** @fastly/js-compute 4.0.1  
**Since:** 3.9.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L24

A low-level API for constructing and manipulating HTTP message bodies outside of the standard Fetch API.

**Note**: Can only be used when processing requests, not during build-time initialization.

```js
import { FastlyBody } from 'fastly:body';

addEventListener('fetch', (event) => {
  const body = new FastlyBody();
  body.append('Hello, ');
  body.append('world!');
  const chunk = body.read(1024);
  event.respondWith(new Response(chunk, { status: 200 }));
});
```

## Constructor

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L28

```javascript
new FastlyBody()
```

Creates a new, empty `FastlyBody` instance.

## Methods

### abandon

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L77

```javascript
abandon(): void
```

Abandons the body, discarding its contents without finalizing.
Unlike [close](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/body/class.FastlyBody/#method-close), this signals that the body is being discarded rather than completed.

**Returns**

`void`

### append

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L55

```javascript
append(data: BodyInit): void
```

Appends data to the end of this body.

**Parameters**

- `data`: `BodyInit` — The data to append.

**Returns**

`void`

**Throws**

- `TypeError` if `data` is a guest-backed `ReadableStream` (not yet supported),
  or if the `ReadableStream` is unusable (locked or already read from).

### close

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L69

```javascript
close(): void
```

Closes the body, signaling that no more data will be written.

**Returns**

`void`

### concat

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L37

```javascript
concat(dest: FastlyBody): void
```

Appends the contents of another `FastlyBody` to this body.
The `dest` body is consumed by this operation and should not be reused.

**Parameters**

- `dest`: `FastlyBody` — The `FastlyBody` to append to this body.

**Returns**

`void`

**Throws**

- `Error` if `dest` is not a `FastlyBody` instance.

### prepend

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L64

```javascript
prepend(data: BodyInit): void
```

Prepends data to the beginning of this body.

**Parameters**

- `data`: `BodyInit` — The data to prepend.

**Returns**

`void`

**Throws**

- `TypeError` if `data` is a guest-backed `ReadableStream` (not yet supported),
  or if the `ReadableStream` is unusable (locked or already read from).

### read

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/body.d.ts#L46

```javascript
read(chunkSize: number): ArrayBuffer
```

Reads up to `chunkSize` bytes from the body, advancing the read position.
Returns an empty `ArrayBuffer` when no more data is available.

**Parameters**

- `chunkSize`: `number` — The maximum number of bytes to read. Must be a positive number.

**Returns**

`ArrayBuffer`

**Throws**

- `Error` if `chunkSize` is not a positive number, is `NaN`, or is `Infinity`.
