restfn templating functions give access to REST clients. Clients must be configured and declared adequately with the REST client module. For better understanding please read configuration and service interface declaration.

Get service

Retrieves an instance of the declared service interface. Instance is created by the configured client factory. (See rest client configuration.)

Method signature

Object getService(String restClientName, String restClientServiceClass)

Arguments

restClientName

required

The name of the configured client.

restClientServiceClass

required

The fully qualified class name of the declared service interface for the client.

Returns

An Object. The actual type of the returned object is defined in the service interface method. For example, if the service interface method defines the return type as a JSON object then that's what you get.

Usage

restfn.getService(restClientName, restClientServiceClass )

[#assign jokesService = restfn.getService("icndbClient", "info.magnolia.documentation.modules.restclientexamples.client.IcndbService")]

Call service (with service object)

This restfn method executes a method of the declared service interface and returns an Object according to the return type of the called interface method.

Method signature

Object call(Object service, String methodName, Object... args)

Arguments

service

required

An instance of the declared service. Can be obtained by #getService method.

methodName

required

The name of the method of the service interface.

args

required

A varargs parameter. In FreeMarker context just pass an array of arguments.

Returns

An Object. The actual type of the returned object is defined in the service interface method. For example, if the service interface method defines the return type as a JSON object then that's what you get.

Usage

restfn.call(service, methodName, args)

[#assign jokesService = restfn.getService("icndbClient", "info.magnolia.documentation.modules.restclientexamples.client.IcndbService")]
[#assign params = ["random", "John", "Doe"] /]
[#assign response = restfn.call(jokesService, "joke", params)  /]
[#-- another option: pass the args in brackets: --]
[#assign response = restfn.call(jokesService, "joke", ["random", "Tiger", "Lilly"] )  /]

Call service (with service interface name) 

This method is a variation of the above mentioned. It also executes a method of the declared service interface and returns an Object according to the return type of the called interface method, however the input parameters are different.

Method signature

Object call(String restClientName, String restClientServiceClass, String methodName, Object... args)

Arguments

restClientName

required

The name of the configured client .

restClientServiceClass

required

The fully qualified class name of the declared service interface  for the client.

methodName

required

The name of the method of the service interface.

args

required

A varargs parameter. In FreeMarker context just pass an array of arguments.

Returns

An Object. The actual type of the returned object conforms with the return type of the method of the declared service interface.

Usage

restfn.call(restClientName, restClientServiceClass, methodName, args)


[#assign params = ["random", "John", "Doe"] /]
[#assign response = restfn.call( "icndbClient",  "info.magnolia.documentation.modules.restclientexamples.client.IcndbService",  "joke", params)  /]
[#-- another option: pass the args in brackets: --]
[#assign response = restfn.call( "icndbClient",  "info.magnolia.documentation.modules.restclientexamples.client.IcndbService",  "joke", ["random", "Lisa", "Klein"])  /]



#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))