RestContext クラス
名前空間
使用方法
System.RestContext クラスを使用して、Apex REST メソッドの RestRequest オブジェクトと RestResponse オブジェクトにアクセスします。
サンプル
次の例では、RestContext を使用して、Apex REST メソッドの RestRequest オブジェクトと RestResponse オブジェクトにアクセスする方法を示します。
1swfobject.registerObject("clippy.ApexRESTExampleContext", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17@RestResource(urlMapping='/MyRestContextExample/*')
18global with sharing class MyRestContextExample {
19
20 @HttpGet
21 global static Account doGet() {
22 RestRequest req = RestContext.request;
23 RestResponse res = RestContext.response;
24 String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
25 Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
26 return result;
27 }
28
29}