Difference between revisions of "REST API:exec Resource"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 16: Line 16:
:** 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 key-value pairs.  
:** It can also return a [[Result Class|Result]] object, in which case the value is automatically converted to a string using <tt>result.toString()</tt>.
:** It can also return a [[Result Class|Result]] object.
{{TBD|yes?}}


;Method:POST
;Method:POST
Line 37: Line 38:
   
   
;Response:
;Response:
:When the return value is a Map, it contains the key/value pairs are those returned by the method.
:When the return value is [[Result]] object, an XML response looks like this:
:When the return value is converted to a string, the response looks like this:
:<syntaxhighlight lang="xml" enclose="div">
:<syntaxhighlight lang="xml" enclose="div">
<platform>
<platform>
Line 50: Line 50:
</platform>
</platform>
</syntaxhighlight>
</syntaxhighlight>
{{TBD|Additional values in Result object?}}
:When the return value is a Map, the key/value pairs it contains are returned. An XML response looks like this:
:<syntaxhighlight lang="xml" enclose="div">
<platform>
    <execClass>
        <key1>value1</key1>
        <key2>value2</key2>
    </execClass>
    ...
</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.

Revision as of 23:12, 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 either take no arguments: public methodName()
    • Or it take arguments passed in a Map: public methodName(Map params)
      (Parameters passed in the Request are wrapped in a Map, and passed to the method.)
  • Return Types:
    • A method may return void.
    • If the return type is a Map, it can be used to return key-value pairs.
    • It can also return a Result object.

__TBD: yes?__

Method
POST
URI
https://{yourDomain}/networking/rest/class/operation/exec
Request
<platform>
    <execClass>
        <clazz>fully.qualified.JavaClassName</clazz>
        <method>methodName</method>
        ...optional list of additional parameter tags like these...
        <firstName>Peter</firstName>
        <lastName>Smith</lastname>
    </execClass>
</platform>
(Note that the items in the <execClass> tag form a flat structure.)
Response
When the return value is Result object, an XML response looks like this:
<platform>
    <execClass>
        <result>...result-string here...</result>
    </execClass>
    <message>
        <code>0</code>
        <description>Success</description>
    </message>
</platform>

__TBD: Additional values in Result object?__

When the return value is a Map, the key/value pairs it contains are returned. An XML response looks like this:
<platform>
    <execClass>
        <key1>value1</key1>
        <key2>value2</key2>
    </execClass>
    ...
</platform>
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.