---
schema_version: "1"
id: 33fafeefa2034069374b99088a3a7c4bbc854478c2634afcfe267bde2223ca40
title: RestResponse Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_methods_system_restresponse.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: ab4613968929e4b385380da89bb1cc8a9b8bef9f1f06fd95a7396cdf280e7fbd
description: Represents an object used to pass data from an Apex RESTful Web service method to an HTTP response.Creates a new instance of the System.RestResponse class.Returns or sets the body of the response.Returns the headers to be sent to the response.Returns or sets the response status code.Adds a header to the response header map.
---
# RestResponse Class

Represents an object used to pass data from an Apex RESTful Web service method to an HTTP response.

## Namespace

[System](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_System.htm "The System namespace provides classes and methods for core Apex functionality.")

## Usage

Use the System.RestResponse class to pass response data from an Apex RESTful web service method that is defined using one of the [REST annotations](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_classes_annotations_rest.htm).

- **[RestResponse Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestResponse_constructors)**
- **[RestResponse Properties](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestResponse_Properties)**
- **[RestResponse Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestResponse_methods)**

## RestResponse Constructors

The following are constructors for RestResponse.

- **[RestResponse()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestResponse_ctor)**  
    Creates a new instance of the System.RestResponse class.

### RestResponse()

Creates a new instance of the System.RestResponse class.

#### Signature

public RestResponse()

## RestResponse Properties

The following are properties for RestResponse.

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/images/icon_note.png)

#### Note

Although the RestResponse Map properties are read-only, their contents are read-write. To modify a RestResponse header, use the associated addHeader method instead of the modifying the Map values directly.

- **[responseBody](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestRequest_responseBody)**  
    Returns or sets the body of the response.
- **[headers](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestResponse_headers)**  
    Returns the headers to be sent to the response.
- **[statusCode](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestResponse_statusCode)**  
    Returns or sets the response status code.

### responseBody

Returns or sets the body of the response.

#### Signature

public Blob responseBody {get; set;}

#### Property Value

Type: [Blob](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_blob.htm#apex_methods_system_blob "Contains methods for the Blob primitive data type.")

#### Usage

The response is either the serialized form of the method return value or it's the value of the responseBody property based on the following rules:

- If the method returns void, then Apex REST returns the response in the responseBody property.
- If the method returns a value, then Apex REST serializes the return value as the response. If the return value contains fields with null value, those fields are not serialized in the response.

### headers

Returns the headers to be sent to the response.

#### Signature

public Map<String, String\> headers {get; set;}

#### Property Value

Type: [Map](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_map.htm#apex_methods_system_map "Contains methods for the Map collection type.")<[String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type."), [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")\>

### statusCode

Returns or sets the response status code.

#### Signature

public Integer statuscode {get; set;}

#### Property Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Status Codes

The following are valid response status codes. The status code is returned by the RestResponse.statusCode property.

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/images/icon_note.png)

#### Note

If you set the RestResponse.statusCode property to a value that's not listed in the table, then an HTTP status of 500 is returned with the error message “Invalid status code for HTTP response: nnn” where nnn is the invalid status code value.

| Status Code | Description |
| --- | --- |
| 200 | OK |
| 201 | CREATED |
| 202 | ACCEPTED |
| 204 | NO\_CONTENT |
| 206 | PARTIAL\_CONTENT |
| 300 | MULTIPLE\_CHOICES |
| 301 | MOVED\_PERMANENTLY |
| 302 | FOUND |
| 304 | NOT\_MODIFIED |
| 400 | BAD\_REQUEST |
| 401 | UNAUTHORIZED |
| 403 | FORBIDDEN |
| 404 | NOT\_FOUND |
| 405 | METHOD\_NOT\_ALLOWED |
| 406 | NOT\_ACCEPTABLE |
| 409 | CONFLICT |
| 410 | GONE |
| 412 | PRECONDITION\_FAILED |
| 413 | REQUEST\_ENTITY\_TOO\_LARGE |
| 414 | REQUEST\_URI\_TOO\_LARGE |
| 415 | UNSUPPORTED\_MEDIA\_TYPE |
| 417 | EXPECTATION\_FAILED |
| 500 | INTERNAL\_SERVER\_ERROR |
| 503 | SERVER\_UNAVAILABLE |

## RestResponse Methods

The following are instance methods for RestResponse.

- **[addHeader(name, value)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_System_RestResponse_addHeader)**  
    Adds a header to the response header map.

### addHeader(name, value)

Adds a header to the response header map.

#### Signature

public Void addHeader(String name, String value)

#### Parameters

- **name**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
- **value**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

#### Return Value

Type: Void

#### Usage

The following headers aren't allowed:

- cookie
- set-cookie
- set-cookie2
- content-length
- authorization
- Header names that aren't RFC 7230 compliant

If any of these headers are used, an Apex exception is thrown.