---
schema_version: "1"
id: 386f8d12e059d472f0177c3d46af0319b5a215051e94e5623df98a795239f5b7
title: RestContext Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_methods_system_restcontext.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restcontext.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7f7e1a1ca1655ff20b71cdd4df01b2e9e75f453dcbf9c3144fccc46f065887f5
description: Contains the RestRequest and RestResponse objects.Returns the RestRequest for your Apex REST method.Returns the RestResponse for your Apex REST method.
---
# RestContext Class

Contains the RestRequest and RestResponse objects.

## 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.RestContext class to access the RestRequest and RestResponse objects in your Apex REST methods.

## Sample

The following example shows how to use RestContext to access the RestRequest and RestResponse objects in an Apex REST method.

@RestResource(urlMapping='/MyRestContextExample/\*')
global with sharing class MyRestContextExample {

    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = \[SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId WITH USER\_MODE\];
        return result;
    }
  
}

## RestContext Properties

The following are properties for RestContext.

- **[request](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restcontext.htm#apex_System_RestContext_request)**  
    Returns the RestRequest for your Apex REST method.
- **[response](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restcontext.htm#apex_System_RestContext_response)**  
    Returns the RestResponse for your Apex REST method.

### request

Returns the RestRequest for your Apex REST method.

#### Signature

public RestRequest request {get; set;}

#### Property Value

Type: [System.RestRequest](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restrequest.htm#apex_methods_system_restrequest "Use the System.RestRequest class to access and pass request data in a RESTful Apex method.")

### response

Returns the RestResponse for your Apex REST method.

#### Signature

public RestResponse response {get; set;}

#### Property Value

Type: [System.RestResponse](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_restresponse.htm#apex_methods_system_restresponse "Represents an object used to pass data from an Apex RESTful Web service method to an HTTP response.")