
Ask HN: Temporal, RESTful-API / different resource types - lichtenberger
Hi,<p>for a temporal Open Source NoSQL storage system I&#x27;m currently changing a RESTful-API slightly (no stable version released as of now -- or way back a few years, so I can change the API) as I now support the storage and querying (querying as of now via XQuery only XML) of either XML or JSON data in a binary- and in-memory format.<p>Would you simply build URLs as for instance with the following schema (and query parameters):<p>https:&#x2F;&#x2F;host:port&#x2F;xml&#x2F;database&#x2F;document
https:&#x2F;&#x2F;host:port&#x2F;json&#x2F;database&#x2F;document<p>or use the HTTP &quot;accept&quot; and &quot;Content-Type&quot; headers? Basically I just need to know if I have to open a database which has XDM&#x2F;XML nodes&#x2F;records stored or JSON nodes, but it affects the RESTful-API.<p>Up until now I simply had URLs in this format:<p>https:&#x2F;&#x2F;host:port&#x2F;database
https:&#x2F;&#x2F;host:port&#x2F;database&#x2F;document<p>kind regards
Johannes
======
sandreas
What you are trying to do is called "content negotiation", afaik
([https://en.wikipedia.org/wiki/Content_negotiation](https://en.wikipedia.org/wiki/Content_negotiation)).
Perhaps you find more information about it, when you use this term.

I like the header approach, because it is nice and clean and it can be applied
easily to an xhr abstraction in JavaScript, without much change.

But to make a resource absolutely idempotent in a more expressive way (which
would be nice), you could also use a file-extension-like apporach:

[http://host:port/database/document.json](http://host:port/database/document.json)

or use a parameter-based one:

[http://host:port/database/document?format=json](http://host:port/database/document?format=json)

------
verdverm
Many frameworks have plugging or middleware that can automate content
negotiation for you too. Using one of those will likely inform your decisions.

I have not seen it as part of the path before, that seems weird, would avoid
that method.

