Passing API templates

In REST requests, the _templateKey and _templateId parameters reference templates that are stored in the database. Because the templates are accessed by reference, REST requests that use templates are lightweight, and multiple users can share a single centrally managed template.

Managing templates in the database

You can create, read, update, and delete API templates with three APIs. For detailed information about these APIs, view the API Javadoc files.

  • manageApiTemplate
  • getApiTemplateDetails
  • getApiTemplateList

You can access "ApiTemplate" APIs by specifying the resource name api_template in REST Detail, List, Modify, Create, or Delete requests.

The following example shows a REST Create request for an API template:
POST http://host:port/contextRoot/restapi/api_template

The PLT_API_TEMPLATE table is used to store the XML-based API and Resource templates. The description is as follows:

Entry Description
ORGANIZATION_CODE Organization identifier that is used in multi-tenant architectures
TEMPLATE_TYPE

00 for an API Template.

The value of TEMPLATE_TYPE is 00 to store the API templates in the database. For example, if you want to store a template for the getOrderList API, then you must pass the TemplateType attribute as 00 in the input to the API. Later, when you pass a templateKey or templateId while calling the getOrderList API, the system searches the PLT_API_TEMPLATE table for templates of type 00 and then uses the template.

01 for a Resource template.

The value of TEMPLATE_TYPE is 01 to store the templates residing in the "resources" directory into the database. For example, apifactlookup.xml, the UI theme template XML, and so on.

API_NAME Name of the API or Resource
TEMPLATE_ID Identifier within the org+type+name
DESCRIPTION Extra description information
TEMPLATE_DATA Character Large Object column that contains the template

Referencing templates

Request specific templates in any API call in the YFSEnvironment with the method:
public void setApiTemplate(String apiName, String templateFileName)
To reference a template from the REST layer, use a query parameter that matches the format of templateFileName:
templateFileName format REST query parameter format
"key:primaryKey" _templateKey=primaryKey
"id:orgCode,templateId" _templateId=orgCode,templateId
Note: The orgCode attribute is optional and defaults to DEFAULT.