Difference between revisions of "REST API:exec Resource"
From AgileApps Support Wiki
imported>Aeric |
imported>Aeric |
||
(14 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
:* A [[Class]] must be defined. (The <tt>exec</tt> resource invokes a method in the class.) | :* A [[Class]] must be defined. (The <tt>exec</tt> resource invokes a method in the class.) | ||
:* An instance of the class is created automatically, so the method need not be <tt>static</tt>. | :* An instance of the class is created automatically, so the method need not be <tt>static</tt>. | ||
:* Whether passed in XML or JSON, parameters passed to the method in the <tt><execClass></tt> segment must consist of a flat structure, as in the example that follows. (The structure is converted to a HashMap, so it cannot contain any complex elements or attributes.) | |||
:* Signatures: | :* Signatures: | ||
:** The method must be <tt>public</tt> | :** The method must be <tt>public</tt> | ||
:** The method can take no arguments: <tt>public methodName()</tt> | :** The method can take no arguments: <tt>public methodName()</tt> | ||
:** | :** Or it take arguments passed in a Map: <tt>public methodName(Map params)</tt><br>(Parameters passed in the REST request shown below are wrapped in a Map, and passed to the method.) | ||
:* Return Types: | :* Return Types: | ||
:** A method may return void. | :** A method may return void. | ||
:** If the return type is a Map, it can be used to return key-value pairs. | :** If the return type is a Map, it can be used to return multiple key-value pairs. | ||
:** | :** Any other return is automatically converted to a String, using <tt>Object.toString()</tt>. The string value is returned with key = <tt>result</tt>. | ||
;Method:POST | ;Method:POST | ||
;URI:<tt> | ;URI:<tt>{{platformURL}}/rest/class/operation/exec</tt> | ||
;Request: | ;Request: | ||
Line 25: | Line 26: | ||
<platform> | <platform> | ||
<execClass> | <execClass> | ||
<clazz> | <clazz>com.platform.yourCompany.yourApplication</clazz> | ||
<method>methodName</method> | <method>methodName</method> | ||
...optional list of | ...optional list of additional parameters like these... | ||
<firstName>Peter</firstName> | <firstName>Peter</firstName> | ||
<lastName>Smith</lastname> | <lastName>Smith</lastname> | ||
Line 33: | Line 34: | ||
</platform> | </platform> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
:(Note that the items in the <tt><execClass></tt> tag form a flat structure.) | |||
;Response: | ;Response: | ||
: | :For a method that returns a Map, the returned structure looks like this: | ||
:<syntaxhighlight lang="xml" enclose="div"> | :<syntaxhighlight lang="xml" enclose="div"> | ||
<platform> | <platform> | ||
<execClass> | <execClass> | ||
< | <clazz>com.platform.yourCompany.yourApplication</clazz> | ||
<method>methodName</method> | |||
<key1>value1</key1> | |||
<key2>value2</key2> | |||
... | |||
</execClass> | </execClass> | ||
<message> | <message> | ||
Line 48: | Line 53: | ||
</platform> | </platform> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
:For a method that returns anything else, the returned structure looks like this: | |||
:<syntaxhighlight lang="xml" enclose="div"> | |||
<platform> | |||
<execClass> | |||
<clazz>com.platform.yourCompany.yourApplication</clazz> | |||
<method>methodName</method> | |||
<result>...value returned from the method...</result> | |||
</execClass> | |||
<message> | |||
<code>0</code> | |||
<description>Success</description> | |||
</message> | |||
</platform> | |||
</syntaxhighlight> | |||
:In either case, a JSON response will have the same structure, but in {{^JSON}} format. | |||
;Known issue: Null return values are not handled at this time. | ;Known issue: Null return values are not handled at this time. |
Latest revision as of 23:38, 13 March 2014
Provides the ability to execute a class method using the REST API.
- Considerations
-
- A Class must be defined. (The exec resource invokes a method in the class.)
- An instance of the class is created automatically, so the method need not be static.
- Whether passed in XML or JSON, parameters passed to the method in the <execClass> segment must consist of a flat structure, as in the example that follows. (The structure is converted to a HashMap, so it cannot contain any complex elements or attributes.)
- Signatures:
- The method must be public
- The method can take no arguments: public methodName()
- Or it take arguments passed in a Map: public methodName(Map params)
(Parameters passed in the REST request shown below are wrapped in a Map, and passed to the method.)
- Signatures:
- Return Types:
- A method may return void.
- If the return type is a Map, it can be used to return multiple key-value pairs.
- Any other return is automatically converted to a String, using Object.toString(). The string value is returned with key = result.
- Return Types:
- Method
- POST
- URI
- https://{yourDomain}/networking/rest/class/operation/exec
- Request
- <syntaxhighlight lang="xml" enclose="div">
<platform>
<execClass> <clazz>com.platform.yourCompany.yourApplication</clazz> <method>methodName</method> ...optional list of additional parameters like these... <firstName>Peter</firstName> <lastName>Smith</lastname> </execClass>
</platform> </syntaxhighlight>
- (Note that the items in the <execClass> tag form a flat structure.)
- Response
- For a method that returns a Map, the returned structure looks like this:
- <syntaxhighlight lang="xml" enclose="div">
<platform>
<execClass>
<clazz>com.platform.yourCompany.yourApplication</clazz>
<method>methodName</method>
<key1>value1</key1>
<key2>value2</key2>
...
</execClass>
<message>
0
<description>Success</description>
</message>
</platform> </syntaxhighlight>
- For a method that returns anything else, the returned structure looks like this:
- <syntaxhighlight lang="xml" enclose="div">
<platform>
<execClass>
<clazz>com.platform.yourCompany.yourApplication</clazz>
<method>methodName</method>
<result>...value returned from the method...</result>
</execClass>
<message>
0
<description>Success</description>
</message>
</platform> </syntaxhighlight>
- In either case, a JSON response will have the same structure, but in JSON format.
- Known issue
- Null return values are not handled at this time.