What's the best way retrieve complex queries from a REST service?
Suppose I want to get X collections, apply filters and equations to each one, combine the collections using some other operation and return one result, everything in one request.
It is just too complex (and big) to put everything in the querystring since I could combine more than 300 collections (plus the operators and filters to each one).
I thought about using POST to send a XML object describing the query to something like:
http://mydomain/collections/complexQuery
It would return an unique ID and then I could use GET to retrieve the complexQuery result:
http://mydomain/collections/complexQuery/{queryId}
Jason S:
That's the idea. The POST will take an XML representation of the query, with the "where" parameters already (they can be too many). The query will be executed only when the GET arrives. I could let the query object available just for some time and delete it later.
Is this a good solution? Am I still RESTful doing this?
In HTTP there are five methods that are commonly used in a REST-based Architecture i.e., POST, GET, PUT, PATCH, and DELETE.
Sounds RESTful to me if you're using a unique ID. If the query result set is large you might want to include a way of asking for result set rows M - N where M,N are parameters.
I guess an advantage of your unique ID approach (w/ query definition state stored on the server) is you could use the result of the query as a parameter of another query. Maybe even separate out POSTING the definition of a query from the execution of the query.
This is the standard RESTful approach. POST
to the resource and expect a 201 Created
(no entity body) with the URI to the created results in the Location
header. You can also return the results with a 200 OK
response, and optionally a URI pointing to the results for future (de)reference in the response along with a copy of the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With