Example URL for GenericNode REST API call
Working an a custom component I'd like to get the category of the current node. Currently I need to check which page type I'm on and then use the appropriate REST call for that page type:
<#if page.name == "CategoryPage"> <#assign category = rest("/categories/id/${coreNode.id}/category/id").value /> <#elseif page.name == "ForumPage > <#assign category = rest("/boards/id/${coreNode.id}/category/id").value /> ...
REST API Javadocs know a "GenericNodes" class which seems to be inherited by Boards, Categories, Blogs, etc. Unfortunately the JavaDocs are missing example urls for how to call the generic nodes' methods. If tried these without success:
http://example.lithium.com/example/restapi/vc/genericnodes/id/NodeID http://example.lithium.com/example/restapi/vc/node/id/NodeID http://example.lithium.com/example/restapi/vc/nodes/id/NodeID
What's the correct url to call the generic nodes' methods?
There are a few "nodes" methods in the Community and Category classes that return either a GenericNode or a list of GenericNodes:
nodes nodes/count nodes/nested nodes/nested/count nodes/type/key/node_type_key nodes/type/key/node_type_key/add nodes/type/key/node_type_key/count nodes/type/key/node_type_key/id/node_id nodes/type/key/node_type_key/nested nodes/type/key/node_type_key/nested/count nodes/type/key/node_type_key/uid/node_uid
However, I'm not sure any of these are going to be useful for what you're trying to do. "nodes/type/key/node_type_key/id/node_id" is probably the cloesest, but you'd have to specify the node type (ie. category, or board), so that kind of defeats the purpose of what you want. I agree, it would be helpful to have a call like "nodes/id/<node id>". The difficulty is that uniqueness of the id is only enforced between nodes of the same type. So you can have a category with category id "bob" and also a board with board id "bob". So that's why you have to specify the node type in the nodes call.
Each node does have a unique "uid", which is an integer. So perhaps a "nodes/uid/<uid>" call would be beneficial?
The approach you have is probably one of the best available currently. One alternative you might consider is using the coreNode.ancestors context object. You can find some more details about it here:
For example, this will give you the id of the parent node from the context in which it is used:
coreNode.ancestors[0].id
You need to be careful about using it on community-level pages (ie. front page, custom pages, etc), though, since they will not have an ancestors node. I'd suggest using freemarker to check for the existance of the object before attempting to read the value.