CallAPI (Alternative method)

You can review the deatils about the alternative method for the CallAPI.

Description

The callAPI JSP tag also supports a way to call APIs within JSPs without defining the API in the Resource Hierarchy tree. If called in this way, different attributes needs to be passed as input to the tag. This alternative method should be used when the input or template of an API call needs to be dynamic based on some conditions within the JSP. Additionally, this alternative method may be used if the input to the API is complicated and cannot be formed using the traditional techniques.

Attributes

apiName - Optional. The name of the API that is called. When using this alternative method of callAPI either apiName or serviceName is required.

suppressInputDecode - Optional. Set the value of this attribute to true, if you want to suppress the recursive html decoding of all the attributes of inputElement as well as all the child elements.

serviceName - Optional. The name of the service (from Service Definition Framework) that is called. Calling a service does not support passing templates. When using this alternative method of callAPI, either serviceName or apiName is required.

inputElement - Required when using this alternative method. A YFCElement representing the input element that is to be passed to the API.

templateElement - Conditionally required. A YFCElement representing the output template expected for the API. When using this alternative method, if the apiName attribute is used, then templateElement is required. If serviceName is used, then templateElement is ignored.

outputNamespace - Optional. The namespace under which the output of the API is placed.

The output of the API is saved in this namespace. Namespace is optional, but if it is not specified, it is defaulted to the root node name of the XML under consideration. Therefore, while referring to the output of the API, even if namespace is not specified here, it can be assumed to be the same as the root node name of the output.

A namespace is a tag that can be used to identify a specific XML. The Presentation Framework enables you to call multiple APIs and store the outputs in different namespaces. In your JSP or in the input to an API, you can refer to values from any namespace that is available at that point.

inputNamespace - Optional. The input namespace is used to dynamically resolve additional input to the API. For more information about input namespace see "Passing Data to APIs."

Body

None.

Example

The following example shows how the getOrderDetails() API can be called from within a JSP without defining an API resource in the Resource Hierarchy tree. Note how the input and template elements are formed in the JSP before the callAPI tag is used. After the callAPI tag call, the output of the getOrderDetails() API is available in the RelatedFromOrderDetails namespace that can be used later on within the JSP.

<%
  YFCDocument inputDoc = YFCDocument.parse("<Order 
OrderHeaderKey=\"xml:/Document/@RelatedFromOrderHeaderKey\"/>"); 
YFCDocument templateDoc = YFCDocument.parse("<Order EnterpriseCode=\"\" 
OrderHeaderKey=\"\"
OrderNo=\"\"
   Status=\"\" BuyerOrganizationCode=\"\" SellerOrganizationCode=\"\" 
OrderDate=\"\" RulesetKey=\"\" HoldFlag=\"\" DocumentType=\"\" 
isHistory=\"\"/>"); 
%> 
<yfc:callAPI apiName='getOrderDetails' 
inputElement='<%=inputDoc.getDocumentElement()%>' 
templateElement='<%=templateDoc.getDocumentElement()%>'
outputNamespace='RelatedFromOrderDetails'/>