Hi All,

Currently i'm implementing a REST API for taxonomy feature [1] . Its need
to render a tree structure in Store view. So we are providing REST api to
generate tree structure. We are reading XML file to generate this tree
structure. After discussion we decided to have following kind of REST API.

Get root node

GET

 apis/taxa

   -

   This will return root node and its all children. (It will not return
   grandchildren of root node) with pagination


Get sub nodes

GET   apis/taxa?path=WSO2/Engineering

   - This will return all children nodes of given node. (It will not return
   grandchildren of given node) with pagination


So, when implementing this scenario , AFAIK i have two solutions to
implement this. *To retrieve all child nodes of given node,* In back end
implementation,

   - Use this REST call (apis/taxa?path=WSO2/Engineering) , Then read the
   query parameter and and convert it into correct xpath expression
   (/WSO2/Enigneering/*). Then return the results with JSON response.

   - Other way is to use (apis/taxa?path=/WSO2/Engineering/*) . In here we
   are directly allowing API user to pass the xpath. Then we create the
   generic response json object.

If we use 2nd method that is pass xpath directly, Our REST API will  more
expandable. User will have wide range of queries to use. As well as in
future implementations,  if we want to add some custom attributes to that
main XML file, we can do it without API level modification. But if we use
this, User who is using this api need to aware about xpath expressions.
However we always providing a documentation to use our apis. In
documentation we can provide general use cases.


*Question is : I don't know whether providing  xpath as parameter in REST
API is a good practice or not.*


   1.
   
https://docs.google.com/a/wso2.com/document/d/1gU0KCCb595kJ0-B9ERMYmIbducZO3-4OCAGf0coZCs4/edit?usp=sharing

Please advice.

Regards




*Lahiru J Ekanayake**Software Engineer*
Mobile : +94 (0) 77 8812629 / +94(0) 778509547
Email : [email protected]
WSO2, Inc.; http://wso2.com/
lean . enterprise . middleware.
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to