Magnolia 5.4 reached end of life on November 15, 2018. This branch is no longer supported, see End-of-life policy.
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.
Retrieves an instance of the declared service interface. Instance is created by the configured client factory. (See rest client configuration.)
Object getService(String restClientName, String restClientServiceClass)
restClientName | required The name of the configured client. |
restClientServiceClass | required The fully qualified class name of the declared service interface for the client. |
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.
restfn.getService(restClientName, restClientServiceClass )
[#assign jokesService = restfn.getService("icndbClient", "info.magnolia.documentation.modules.restclientexamples.client.IcndbService")]
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.
Object call(Object service, String methodName, Object... args)
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. |
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.
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"] ) /]
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.
Object call(String restClientName, String restClientServiceClass, String methodName, Object... args)
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. |
An Object. The actual type of the returned object conforms with the return type of the method of the declared service interface.
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"]) /]