restfn templating functions give access to REST clients configured
with the REST Client
module.
accessing 3rd party systems with REST
Using Magnolia REST clients with restfn in FTL template scripts could
slow or even block the rendering of the scripts, because the call is
synchronous and waits till the request returns. Before an actual
implementation, always consider at least the following:
The reliability of the endpoint.
Implementing restfn in an asynchronous way via a client side
request.
Accessing the endpoint directly with client side code.
How any of your page caching configurations will affect content
delivered from restfn.
Call response
Invokes a call for a full response to a configured REST client, with
optional assignment of custom template values for request parameters or
body, and with optional specific error handler.
Returns a full response as a map of clients and call names, with error
handlers and/or custom template values, if available.
The return type of restfn depends on the entityClass configured for the respective REST call. If the entityClass returns a JSON node com.fasterxml.jackson.databind.JsonNode, see Client configuration and Component template script for more information.
The form of the restCallName
By default, the name is mapped to this pattern:
method:/path/pathAction. An
operationId, a
unique string used to identify the operation in
the OpenAPI specification, is an
optional alias for the call name.
In the following configuration snippet, an operationId has been set to
findByStatus:
Converts a JsonNode object to a hash map. Use either this or the
asList() function depending on what type
of JSON the API your query returns.
Returns a hash map.
Method signature
Map<String, Object> asMap(jsonNode)
Arguments
Argument
Description
jsonNode
required
Variable of type com.fasterxml.jackson.databind.JsonNode.
Usage
restfn.asMap(jsonNode)
[#assign colombia = restfn.asMap(restfn.call("countries", "colombia"))]
[#-- Note: Provided the restfn.call("countries", "colombia") is defined
using the com.fasterxml.jackson.databind.JsonNode entity class.--]
Copy
Convert JsonNode to List
Converts a JsonNode object to an array list. Use either this or the
asMap() function depending on what
type of JSON the API your query returns.
Returns an array list.
Method signature
List<Object> asList(jsonNode)
Arguments
Argument
Description
jsonNode
required
Variable of type com.fasterxml.jackson.databind.JsonNode.
Usage
restfn.asList(jsonNode)
[#assign countriesList = restfn.asList(restfn.call("countries", "allCountriesArray"))]
[#-- Note: Provided the restfn.call("countries", "allCountriesArray") is defined
using the com.fasterxml.jackson.databind.JsonNode entity class.--]