Tag: rest
The wcf:rest
tag
sends REST requests.
This JSP tag takes
input and sends out REST requests, and then composes responses in a specified format. A REST tag,
which is defined as a template, does not send out REST requests but persist its parameters in memory
as default input. Then, it provides a mechanism that can reuse the template without identifying all
parameters, only the modified ones. This approach is similar to the expressionBuilder in the
wcf:getData
tag REST access profile. A parameter is passed in to the REST tag to
determine the server calculation, and how much detailed data is being queried for the resource. It
supports two format types. One format type is the same as the traditional access profile and search
profile in a web service, a meaningful string that indicates the querying details. While the other
format type is a detailed one, which identifies all required fields of the resource.
One REST
tag might have multiple param tags. These tags are composed into the REST request to the REST server
as a request parameter or request body, which include common parameters such as langId, currency,
pageSize wcf:header
.
One REST tag might have multiple header tags. These tags are composed into the REST request to the REST server as a request header, which includes parameters such as WCToken and WCTrustedToken.
The wcf:rest
tag caches REST API calls at
the request-level by using the call signature. For more information, see Caching strategies for REST services.
Tag information | |
---|---|
Body Content | JSP |
Attributes
Name | Required | Request-time | Type | Description |
---|---|---|---|---|
var |
false |
true |
java.lang.String |
This parameter identifies the variable name, which will be used to be put into persistent scope like session or request. When the tag is declared as a template, this parameter can be ignored. |
url |
false |
true |
java.lang.String |
This parameter identifies the actual URL of the REST service. This parameter supports absolute or relative addresses. For relative addresses, a developer must identify the path that begins from the resource name. The system adds the host name, servlet path, and store name automatically. For relative addresses, a developer also needs to specify the http schema, which defaults to "http". |
schema |
false |
true |
java.lang.String |
This parameter specifies the schema when the URL parameter is not an absolute path. The tag system gets some default value from configuration as the host name, context path and storeId. the schema parameter is specified here. |
accessProfile |
false |
true |
java.lang.String |
The accessProfile is used to invoke the backend web service, which decides how much data is requested, similar to the fields parameter. The access profile is pre-configured on the REST server and cannot be changed. When this parameter is specified, the REST framework uses the transmitted one to replace the default one. |
searchProfile |
false |
true |
java.lang.String |
In catalog-related REST services, searchProfile is used to invoke the backend web service, which decides how much data is requested, similar to the fields parameter. The searchProfile is pre-configured on the REST server and cannot be changed. When this parameter is specified, the REST framework uses the transmitted one to replace the default one. |
format |
false |
true |
java.lang.String |
This parameter decides the output variable's format, which can be json, xml, or raw. Setting the value to json gives an object of type org.apache.wink.json4j.JSONObject, xml gives an object in type org.w3c.dom.Document, and raw gives string. The JSON object is output directly. The default value for this parameter is json. |
cached |
false |
true |
java.lang.String |
Client-side caching can be used with Storefront JSP files if the REST
service that is being called is marked as cacheable . (Note that in the case of the
Aurora Store, the client is the application server (servlet container) hosting the JSP pages that
include the REST tags, and so caching will occur on the application server, and not in the browser
that is consuming the output of the JSP pages.) In order to use client-side caching, set the value
of cached to "true" . Responses for REST requests are based on the
preceding URL and parameters are cached inside the data cache that is called
RESTTagCache , with the services/cache/WCRESTTagDistributedMapCache
cache JNDI name. This caching is applicable to REST services provided by both WebSphere Commerce
and WebSphere Commerce search servers. |
scope |
false |
false |
java.lang.String |
The scope of the REST service. |
headerStrategy |
false |
false |
java.lang.String |
This parameter decides how the HTTP headers are composed in the tag. The
following values are allowed:
|
connectTimeout |
false |
false |
java.math.BigInteger |
The time to wait, in milliseconds, before an HTTP connection to the target server is established. The default value is 30000. |
readTimeout |
false |
false |
java.math.BigInteger |
The time to wait, in milliseconds, before a response is obtained. The default value is 30000. |
Subtags
wcf:rest
tag contains the following subtags:wcf:header
, which adds an HTTP header to a REST request.wcf:var
, which sets the variable within a REST request.
Variables
No variables are defined for the wcf:rest
tag.
Example
Normal usage to get a product
<wcf:rest var="product" url="productview/byId/10001"/>