Access the REST API operation information, REST API operation parameters, and REST API request and response body.
Information about the current operation is automatically placed into the local environment tree. You can use this information in your implementation if you want to determine which operation in the REST API was called, which HTTP method was used, the request path, or the request URI. For example, if you are sharing transformation logic across multiple operations, you can use this information to determine in which operation the REST API was called.
When you create the message map by using the option Message map with input and output for REST API operation, the local environment is automatically added to the map input and any path or query parameters are added. A Task transform is pre-wired to , to help you locate this information. For more information, see Implementing a REST API operation by using a message map.
Check to see if the current operation was called by using an HTTP GET.
IF InputLocalEnvironment.REST.Input.Method = 'GET' THEN
-- Executed only if the current operation was called using an HTTP GET.
END IF;
Check to see if the current operation is the getAllCustomers operation.
IF InputLocalEnvironment.REST.Input.Operation = 'getAllCustomers' THEN
-- Executed only if the current operation is the getAllCustomers operation.
END IF;
Create a log message with the request path.
DECLARE logMessagePath CHARACTER 'Received request on path ' || InputLocalEnvironment.REST.Input.Path;
Create a log message with the request URI.
DECLARE logMessageURI CHARACTER 'Received request on URI ' || InputLocalEnvironment.REST.Input.URI;
Check to see if the current operation was called by using an HTTP GET.
MbMessage inLocalEnvironment = inAssembly.getLocalEnvironment();
MbElement leRestInput = inLocalEnvironment.getRootElement().getFirstElementByPath("/REST/Input");
if (leRestInput.getFirstElementByPath("Method").getValueAsString().equals("GET")) {
// Executed only if the current operation was called using an HTTP GET.
}
Check to see if the current operation is the getAllCustomers operation.
if (leRestInput.getFirstElementByPath("Operation").getValueAsString().equals("getAllCustomers")) {
// Executed only if the current operation is the getAllCustomers operation.
}
Create a log message with the request path.
String logMessagePath = "Received request on path " + leRestInput.getFirstElementByPath("Path").getValueAsString();
Create a log message with the request URI.
String logMessageURI = "Received request on URI " + leRestInput.getFirstElementByPath("URI").getValueAsString();
Check to see if the current operation was called by using an HTTP GET.
NBMessage inLocalEnvironment = inputAssembly.LocalEnvironment;
NBElement leRestInput = inLocalEnvironment.RootElement["REST"]["Input"];
if (((String) leRestInput["Method"]) == "GET"){
// Executed only if the current operation was called using an HTTP GET.
}
Check to see if the current operation is the getAllCustomers operation.
if (((String) leRestInput["Operation"]) == "getAllCustomers") {
//Executed only if the current operation is the getAllCustomers operation.
}
Create a log message with the request path.
String logMessagePath = "Received request on path " + ((String) leRestInput["Path"]);
Create a log message with the request URI.
String logMessageURI = "Received request on URI " + ((String)leRestInput["URI"]);
If the definition of an operation includes one or more parameters, the names and values of those parameters are automatically placed into the local environment tree, but only if those parameters are provided by the HTTP client that is calling the operation. Optional or missing parameters are not placed into the local environment tree. Parameters are always placed into the local environment tree as character (string) elements, where the name of each element is the name of the parameter and the value of the element is the value of the parameter.
When you create the message map by using the option Message map with input and output for REST API operation, the local environment is automatically added to the map input and any path or query parameters are added under , ready for you to connect transforms. A Task transform is pre-wired to , to help you locate this information. For more information, see Implementing a REST API operation by using a message map. If you update the REST API and change the path or query parameters, the message map is updated with the new definitions when it is reopened. If there were existing transforms wired to the parameters, they might need to be modified.
If you do not use the option Message map with input and output for REST API operation, you must add the local environment manually, and in the Parameters folder use the any element to add user-defined elements. For more information, see Mapping data in the local environment tree and Defining user-defined elements.
Check to see if the parameter named 'max' is supplied.
DECLARE max INTEGER -1;
IF FIELDTYPE(InputLocalEnvironment.REST.Input.Parameters.max) IS NOT NULL THEN
SET max = InputLocalEnvironment.REST.Input.Parameters.max;
END IF;
Check to see if the parameter named 'max' is supplied.
MbElement maxElement = inLocalEnvironment.getRootElement().getFirstElementByPath("/REST/Input/Parameters/max");
int max = -1;
if (maxElement != null) {
max = Integer.valueOf(maxElement.getValueAsString());
}
Check to see if the parameter named 'max' is supplied.
NBElement maxElement = inLocalEnvironment.RootElement["REST"]["Input"]["Parameters"]["max"];
int max = -1;
if (max != null){
max = (int) maxElement;
}
Depending on the HTTP method of the operation, the operation can accept data from the HTTP client in the request body. REST APIs in IBM® Integration Bus are configured by default to process JSON data. For more information about processing JSON data that was passed in the request body, and creating JSON data to send as the response body, see JSON parser and domain. You can also use a message map to process JSON data. For more information, see Creating or transforming a JSON output message by using a message map.