3 ms·
Ask HN: Temporal, RESTful-API / different resource types
Hi,
for a temporal Open Source NoSQL storage system I'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.
Would you simply build URLs as for instance with the following schema (and query parameters):
https://host:port/xml/database/document
https://host:port/json/database/document
or use the HTTP "accept" and "Content-Type" headers? Basically I just need to know if I have to open a database which has XDM/XML nodes/records stored or JSON nodes, but it affects the RESTful-API.
Up until now I simply had URLs in this format:
https://host:port/database
https://host:port/database/document
kind regards
Johannes
- sandreas 8y agoWhat 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 8y agoMany 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.