REST represenation for xml

i'm building a REST api and debating what format should I use for the xml representation. i know it can be one defined in house but there are also lots for formats. wadl looks interesting but there seems to be a debate about it and it's new as well.

what are the recommendations(best practices for it) ?

thanks

Answers


As long as it's valid XML that's a start. My general strategy for simple REST/XML services is as follows:

For parsing, you almost certainly want a single, always present root node, e.g. "response", which can contain either a result element or an error element. E.g.:

<response>
  <result>
    <answer>5</answer>
  </result>
</response>

The way you structure the results is up to you. You can decide whether to hold data in elemenets as CDATA (text notes, as show above) or as required attributes, e.g.

<answer value="5"/>

Another thing that is sometimes useful is to include your original query in the response, e.g.:

<response query="operation=add&a=2&b=3"> .. </response>

That way if you have multiple queries outstanding you can match them back to the original request.


Need Your Help

Adding constraint to css file for a QWidget

c++ css qt

I use a css file in my Qt Projets, with Visual Studio 2010.

How to select XML element based on tag name using Jquery selectors?

jquery node.js cheerio

If I have an XML document and I am parsing it using Jquery selectors (using the CheerioJS module), how can I grab the value of the value, task, and data tag of the first item without basing it on c...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.