1.Apex REST アノテーション
6 つの新しいアノテーションが追加され、Apex クラスを RESTful Web サービスとして公開できるようにするようになりました。
- RestResource アノテーション
- HttpDelete アノテーション
- HttpGet アノテーション
- HttpPatch アノテーション
- HttpPost アノテーション
- HttpPut アノテーション
【考慮事項】
- URL 対応付けは、https://instance.salesforce.com/services/apexrest/ と相対的です。
- ワイルドカード文字 (*) を使用することができます。
- URL の対応付けでは、大文字と小文字は区別されます。
- このアノテーションを使用するには、Apex クラスがグローバルとして定義されている必要があります。
- HTTP メソッド は global static として定義する。
- それぞれのアノテーションは、各 Apex クラスで 1 回のみ使用できます。
2.実装例
@RestResource(urlMapping='/XXXXXX/*')
global with sharing class XXXXXXRestAPI {
@HttpGet
global static ResponseWrapper doGet() {
ResponseWrapper response = new ResponseWrapper();
try {
// 業務処理
// ~~省略~~
// 正常終了
response.isSuccess = true;
} catch(Exception e){
// 異常終了
response.isSuccess = false;
response.message = 'システムエラーが発生しました。' + e.getMessage();
}
return response;
}
@HttpPost
global static ResponseWrapper doPost(RequestWrapper request) {
ResponseWrapper response = new ResponseWrapper();
try {
// 業務処理
// ~~省略~~
// 正常終了
response.isSuccess = true;
} catch(Exception e){
// 異常終了
response.isSuccess = false;
response.message = 'システムエラーが発生しました。' + e.getMessage();
}
return response;
}
global class RequestWrapper {
Account acct;
}
global class ResponseWrapper {
Boolean isSuccess;
String message;
Account acct;
List<Contact> contList;
}
}
3.Apex Rest API バージョン管理場合の検討
URI Naming Rules(参考)
-
Freeeのエンドポイント構成
※参考資料:https://developer.freee.co.jp/docs/accounting/reference
・勘定科目一覧の取得
https://api.freee.co.jp/account_items
・品目一覧の取得
https://api.freee.co.jp/items -
SFDCのエンドポイント構成
・取引先メータデータの取得
https://xxxxxx.salesfroce.com/services/data/v43.0/sobjects/account/describe) -
MoneyForwardのエンドポイント構成
※参考資料:https://expense.moneyforward.com/api/index.html#/
・自分が所属する事業所一覧を返す
https://expense.moneyforward.com/api/external/v1/offices
・事業所全体の経費明細リストを返す
https://expense.moneyforward.com/api/external/v1/offices/{office_id}/ex_transactions
サンプルソース
~~準備中~~