Title: WP_REST_Server::envelope_response
Published: December 9, 2015
Last modified: August 20, 2026

---

# WP_REST_Server::envelope_response( WP_REST_Response $response, bool|string[] $embed ): 󠀁[WP_REST_Response](https://developer.wordpress.org/reference/classes/wp_rest_response/)󠁿

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#wp--skip-link--target)

Wraps the response in an envelope.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#description)󠁿

The enveloping technique is used to work around browser/client compatibility issues.
Essentially, it converts the full HTTP response to data instead.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#parameters)󠁿

 `$response`[WP_REST_Response](https://developer.wordpress.org/reference/classes/wp_rest_response/)
required

Response object.

`$embed`bool|string[]required

Whether to embed all links, a filtered list of link relations, or no links.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#return)󠁿

 [WP_REST_Response](https://developer.wordpress.org/reference/classes/wp_rest_response/)
New response with wrapped data

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#source)󠁿

    ```php
    public function envelope_response( $response, $embed ) {
    	$envelope = array(
    		'body'    => $this->response_to_data( $response, $embed ),
    		'status'  => $response->get_status(),
    		'headers' => $response->get_headers(),
    	);

    	/**
    	 * Filters the enveloped form of a REST API response.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param array            $envelope {
    	 *     Envelope data.
    	 *
    	 *     @type array $body    Response data.
    	 *     @type int   $status  The 3-digit HTTP status code.
    	 *     @type array $headers Map of header name to header value.
    	 * }
    	 * @param WP_REST_Response $response Original response data.
    	 */
    	$envelope = apply_filters( 'rest_envelope_response', $envelope, $response );

    	// Ensure it's still a response and return.
    	return rest_ensure_response( $envelope );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-server.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/class-wp-rest-server.php#L861)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/class-wp-rest-server.php#L861-L886)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#hooks)󠁿

 [apply_filters( ‘rest_envelope_response’, array $envelope, WP_REST_Response $response )](https://developer.wordpress.org/reference/hooks/rest_envelope_response/)

Filters the enveloped form of a REST API response.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_REST_Server::response_to_data()](https://developer.wordpress.org/reference/classes/wp_rest_server/response_to_data/)`wp-includes/rest-api/class-wp-rest-server.php` |

Converts a response to data to send.

  | 
| [rest_ensure_response()](https://developer.wordpress.org/reference/functions/rest_ensure_response/)`wp-includes/rest-api.php` |

Ensures a REST response is a response object (for consistency).

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#)

| Used by | Description | 
| [WP_REST_Server::serve_batch_request_v1()](https://developer.wordpress.org/reference/classes/wp_rest_server/serve_batch_request_v1/)`wp-includes/rest-api/class-wp-rest-server.php` |

Serves the batch/v1 request.

  | 
| [WP_REST_Server::serve_request()](https://developer.wordpress.org/reference/classes/wp_rest_server/serve_request/)`wp-includes/rest-api/class-wp-rest-server.php` |

Handles serving a REST API request.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_server/envelope_response/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | The `$embed` parameter can now contain a list of link relations to include. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_server%2Fenvelope_response%2F)
before being able to contribute a note or feedback.