3 ms·
This would honestly work better as an 'ask HN', rather than a 'tell HN'. Namely, if this were an Ask HN, I'd tell you to use the new HTTP RFCs [1] instead of t
by niftich 10y ago
This would honestly work better as an 'ask HN', rather than a 'tell HN'.
Namely, if this were an Ask HN, I'd tell you to use the new HTTP RFCs [1] instead of the old ones.
I'm assuming that 'batch requests' means that your HTTP API is a thin proxy that surfaces data from some underlying database, and you want to enhance to be able to operate on more than one underlying resource. In the case of GET, you're retrieving data, so I'm guessing you want to surface more than one resource. I would call that a 'search', while modifying more than one resource with the same request I'd call a 'batch'; please correct me if you feel I'm wrong.
With that in mind, I suggest two approaches to have 'search requests':
[A.] try to express your search filters with key-value pairs, as fundamentally that's what should be going on behind the scenes.
[B.] design a 'Search Manager' endpoint where you can POST a search-request in a complex datatype of your design. This endpoint returns a 201 Created with a Location URI that allows you to retrieve the results.
The suggestion in this programmers exchange post is essentially the same, stated slightly differently [2].
[1] https://tools.ietf.org/html/rfc7231#section-4.1 https://tools.ietf.org/html/rfc7231#section-4.1
[2] http://programmers.stackexchange.com/questions/233164/how-do-searches-fit-into-a-restful-interface http://programmers.stackexchange.com/questions/233164/how-do...
- themihai 10y agoI don't think it's search because the server must provide a response for each resource or an error. If one resource is missing the server should return an error. --- Concerning the post I would move it to `ask HN` but I don't know how to do that. Perhaps I need more karma?
- niftich 10y agoIf you need separate responses for each resource, why not make separate requests in the first place? - OR - You can design a structured format that communicates the information you want. For example, a format based on JSON with an array of objects, or a format based on JSON with an key-value map of objects (ie. object of objects).
- themihai 10y agoWell that's exactly what I need: A format that communicates structured data, friendly with GET requests and backward compatible with query string encoding. Why there is no such format/standard yet? Is it that unusual?
- niftich 10y agoThere are ready-made mediatypes to communicate collections; some have even been registered as mediatypes with IANA. A simple one that would meet your needs is Collection+JSON [1]. There are others. This blog post [2] from 2014 lists some from a hypermedia perspective, although you may find some of these formats excessive for what you're trying to accomplish. Before JSON became a favorite for HTTP APIs, there used to be XML-based ones as well. AtomPub is a very good protocol, which defines an 'application/atomcoll+xml' mediatype for collections [3] [1] http://amundsen.com/media-types/collection/ http://amundsen.com/media-types/collection/ [2] http://sookocheff.com/post/api/on-choosing-a-hypermedia-format/ http://sookocheff.com/post/api/on-choosing-a-hypermedia-form... [3] http://bitworking.org/projects/atom/draft-ietf-atompub-protocol-04.html#collection_resource http://bitworking.org/projects/atom/draft-ietf-atompub-proto...