Thomas Cheng
Thomas Cheng

Reputation: 715

A "long" GET request with many parameters

I'm implementing a restful API interface, and was wondering about some limitations and best practices.

I have a GET request which retrieves a series of entries from a database table.

However my problem is, I allow my callers to pass in quite a complicated set of criteria to filter out what they want.

My situation is:

If I do not want to violate the RESTful API, but would like to achieve my goal of passing over a long query string of parameters, what would be a best practices to solve this?

Any suggestions are welcome. Thank you!

Upvotes: 6

Views: 9920

Answers (1)

Canol Gökel
Canol Gökel

Reputation: 1275

One solution is to do the filtering in the front-end, instead of back-end. So you get all the records via GET request but only show the user the filtered ones. (Of course you don't get the records user does not have permission to see, you filter them server-side)

Advantages:

  • A pure REST solution, you don't send POST request to GET something

  • You make 1 request at the beginning and as the user tries different filters, no additional requests are required

Disadvantages:

  • If the data set is too big, the request might consume a lot of network resource. But this will be a 1 time request since additional filtering won't require new requests. Also, gzipping the response reduces a JSON response's size significantly, so you can send a JSON response with thousands of records via a few hundred KB.

  • If data set is too big, the filtering operation might take a long time in the browser and freeze it temporarily.

So this solution is highly dependent on your use case, but it is one of the solutions. Maybe a hybrid approach might be useful, like doing some of the main filtering on the server side and the rest of the filtering on the client side.

Upvotes: 4

Related Questions