Software AG Products 10.7 | Integrating On-Premises and Cloud Applications | Service Development | webMethods Query Language | Usage Notes on REST | Example of Defining a REST V2 Resource Operation
 
Example of Defining a REST V2 Resource Operation
Consider a discussion application that maintains a database of discussions about different topics. If you want REST clients to interact with this application through Integration Server and read information about discussions related to a specific topic, then create a REST V2 element named discussionNode with the resource name as discussionunder the folder called app. Define a resource operation that supports the HTTP GET method by providing the following details:
*REST URL: /discussion/topic/{id}
*HTTP Methods: GET
Example of Add Operation
If you select an existing Integration Server service named communication to implement the specified resource operation, ensure that the service has a String input variable which corresponds to the dynamic parameter provided in the REST URL (in this case, id).
Based on the information specified, any client request to the REST server must be in the format: GET /rad/app:discussionNode/discussion/topic/{id}, where /rad/app:discussionNode is the template prefix used to invoke the discussion resource, and {id} is a dynamic parameter that accepts any value associated with a specific topic.
A simple REST request looks like this:
METHOD /rad/namespace_of_rad/URL_template HTTP/1.1
Where...
Is the...
METHOD
HTTP request method.
rad
This is a directive which shows the type of processing to perform.
namespace_of_rad
The namespace of the REST API descriptor.
URL_template
The URL template to be used.
Consider a Discussion application that maintains a database of discussions about different topics. Using the URL template-based approach, you can create a REST V2 resource named discussion under the app folder and define resource operations. The following examples show resource operations for the created resource and how Integration Server parses these requests:
Example 1
Consider a REST V2 resource operation configured with the following URL template:
/rad/app:discussionrad/discussion/topic/{id}
Here is an example request to display information about a specific topic:
GET /rad/app:discussionrad/discussion/topic/236 HTTP/1.1
Where...
Is the...
GET
HTTP method supported by the resource operation.
Note:
Integration Server treats this method as valid only if the resource and the underlying service are configured to support the GET method.
rad/app:discussionrad
Template prefix. This informs the type of processing to perform, in this case, Integration Server REST processing, and fully qualified name of the rad element.
Note:
For more information about directives, see
discussion/topic/236
The URL path based on the URL template where the path parameter id is substituted by 236.
Note:
The id parameter must be available as a variable of type String in the input signature of the flow service associated with the resource operation for which you are defining the URL template.
Example 2
Consider a REST V2 resource operation configured with the following URL template:
/rad/app:discussionrad/discussion/topic/{id}/comment/{cid}
Here is a request to display information about a particular comment related to a topic, and how Integration Server parses the request:
GET /rad/app:discussionrad/discussion/topic/1591/comment/4 HTTP/1.1
Where...
Is the...
comment/4
Additional information for the topic with the identifier 1591. Integration Server matches this value with the portion of the request URL after the topic identifier. The value 4 is matched against the dynamic parameter {cid}.