この記事では、
API オブジェクトの [ Service Source ] エレメントで使用する構文について説明します。
<APIName>'{‘
[ ' [ 'Annotation1' ] ' ]
[ ' [ 'Annotation2' ] ' ]
<ServiceName1>(in:&var1, [ in:&var2, inout:&var3, ] out:&var4)=>
<Implementation1>(&var1, [ &var2, &var3, ] &var4);
... [ ' [ 'AnnotationN' ] ' ]
<ServiceNameN>(in:&var5, [ inout:&var6, ] out:&var7)=>
<ImplementationN>(&var5, [ &var6, ] &var7);
'}'
構文の表記規則の表示
入力値の説明:
APIName コード内で API を記述するために使用される名前です。
Annotation1, …, AnnotationN これらは任意のアノテーションです。大括弧と適用する ServiceName の宣言の前の間に記述する必要があります。使用できるアノテーションは、
RestMethod および
RestPath です。
ServiceName1, …, ServiceNameN 外部名です (サービスとして公開される)。
&var1, ..., &varN これらは、サービスのパラメーターである API オブジェクトで定義されている変数です。
Implementation1, …, ImplementationN KB で実装されている GeneXus オブジェクトの名前です。
API オブジェクトで宣言する各サービスには、次のものを指定する必要があります:
- 公開されるサービスの名前 (パラメーターおよび各演算子のタイプも含む)。
- サービスの機能を実装する KB で定義されている GeneXus オブジェクトの名前 (パラメーター、および各演算子のタイプを示す機能を含む)。
各サービスは、外部名とサービスの機能の実装間をマッピングすることによって定義されます。
サービスと実装間のパラメーターの基本的なマッピングは、変数名を使用して行われます。すなわち、サービスのパラメーターと実装間の順序が異なるかどうかは関係ありません。
サービスの最後のパラメーターは戻りパラメーター (サービスが返すもの) ですが、実装ではそれらが最後のパラメーターであるとは限りません。
サービスの宣言では、
IN 演算子を使用した実装で定義されているパラメーターを省くことができます。その場合、サービスの
Before イベントでパラメーターを初期化できます。
同時にサービスの宣言で、実装では記述されていない OUT 演算子を使用してパラーメーターを定義できます。その場合、サービスの
After イベントでパラメーターを初期化できます。
また、オブジェクト内でパラーメーターに IN 演算子が含まれている場合、実装部分で定数がサポートされます。
ビジネスコンポーネントとして定義されている次の
トランザクションがあるとします。
Account
{
AccountId*
AccountOwner
AccountPassword
AccountStatus (Type:Boolean)
}
例 1
アカウント番号およびパスワードを入力し、アカウントおよびアカウントの所有者のステータスを確認するとします。
QueryAccount という
Procedure オブジェクトを作成し、次のように定義します:
変数:
Account (Type:Account)
AccountId (Type:Attribute:AccountId)
AccountOwner (Type:Attribute:AccountOwner)
AccountPassword (Type:Attribute:AccountPassword)
AccountStatus (Type:Attribute:AccountStatus)
ルール:
Parm(in:&AccountId, in:&AccountPassword, out:&AccountOwner, out:&AccountStatus);
ソース:
&Account.Load(&AccountId)
&AccountOwner = &Account.AccountOwner
&AccountStatus = &Account.AccountStatus
APIAccount という API オブジェクト作成し、次のように定義します:
変数:
AccountId (Type:Attribute:AccountId)
AccountOwner (Type:Attribute:AccountOwner)
AccountPassword (Type:Attribute:AccountPassword)
AccountStatus (Type:Attribute:AccountStatus)
サービスソース:
Account{
AccountInfo(in:&AccountId, in:&AccountPassword, out:&AccountStatus, out:&AccountOwner)
=>QueryAccount(&AccountId, &AccountPassword, &AccountOwner, &AccountStatus);
}
AccountInfo は、サービスとして公開される名前です。入力パラメーターは、&Account および &Password です。出力パラメーターは、&Status および &AccountOwner です。
QueryAccount は、KB で定義されているプロシージャーです。変数 &AccountId および &AccountPassword は、プロシージャーで入力パラメーターとして定義されています。変数 &AccountStatus および &AccountOwner は、プロシージャーで出力パラメーターとして定義されています。
また、&AccountStatus および &AccountOwner の順序は、サービスまたはプロシージャーのパフォーマンスには影響しません。
上記の例とのわずかな相違点は、アカウントのステータスのみを返す点です。
Account{
AccountInfo(in:&AccountId, in:&AccountPassword, out:&AccountStatus)
=>QueryAccount(&AccountId, &AccountPassword, &AccountOwner, &AccountStatus);
}
この場合、変数 &AccountOwner は、実装を解決する GeneXus オブジェクトでのみ定義されます。
このタイプの変数を扱う方法は、2つあります:
- API オブジェクトの [ Events ] でこれらの変数を初期化します。すなわち、AccountInfo の Before イベントで &AccountOwner 変数によって取得される値を定義します。
- これらの変数をプロシージャーで入力として定義します。たとえば、以下のように定義します。
parm(in:&AccountId, in:&AccountPassword, inout:&AccountOwner, out:&AccountStatus);
例 2 の別のオプションは、以下のように定数を追加します。
Account{
AccountInfo(in:&AccountId, in:&AccountPassword, out:&AccountStatus)
=>QueryAccount(&AccountId, &AccountPassword, "Tomas Huck", &AccountStatus);
}
&AccountOwnwer 変数は、実装で IN 演算子を使用して定義する必要があります。