Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to create RESTful complex queries?

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?

like image 908
andrecarlucci Avatar asked Dec 19 '08 19:12

andrecarlucci


People also ask

How many ways can you create a RESTful API?

In HTTP there are five methods that are commonly used in a REST-based Architecture i.e., POST, GET, PUT, PATCH, and DELETE.


2 Answers

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.

like image 105
Jason S Avatar answered Oct 15 '22 23:10

Jason S


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.

like image 37
Mark Cidade Avatar answered Oct 15 '22 23:10

Mark Cidade