Forum Discussion
We will be releasing a couple Freemarker context objects for 14.12 that should help with these types of things. For REST V2, we are releasing a new object named apiv2 that will have two functions in it: apiv2.toJson(<your v2 freemarker object>) and apiv2.toxml(<your v2 freemar object>). You'll be able to take a REST V2 response, navigate its object graph, and then print out the object as a JSON or XML string (kind of similar to .@@markup for REST V1). An example:
<#assign liql = "SELECT * FROM messages WHERE board.id = 'studio'" /> <#assign resp = rest("2.0", liql?url) /> <#-- print out the first item in the list of messages --> ${apiv2.toJson(resp.data.items[0])}
We'll also be releasing an object named restd that we already had (just for API V1 XML responses), but that was previously un-documented, and that has been extended to work with JSON for API V1 and V2. The restd object will make a REST API call, but instead of returning a wrapped object response it will return either an XML string or a JSON string, depending on how the call is made.
- ${restd("/boards/id/extensions/topiclist")} will return an XML string version of an API V1 response.
- ${restd("/boards/id/extensions/topiclist", "json")} will return a JSON string version of an API V1 response.
- ${restd("2.0", "/search?q=SELECT+*+FROM+messages")} will return a JSON string version of an API V2 response.
- ${restd("2.0", "/search?q=SELECT+*+FROM+messages", "xml")} will return an XML string version of an API V2 response.
-Doug
Related Content
- 5 years ago
- 5 years ago