HTTP GET request body

I was developing a RESTful API. When done with the basic select/insert/update, I needed to implement endpoints for batch queries. All of a sudden, I was like, how do I pass in the list of ids? Is there some standards out there?

I was thinking of using POST. That was how I did it back then, simple and easy. But with the REST philosophy, or the http way of things, I wanted to stick with GET.

So… how do I pass in a list of ids? I can use the query string, but there is a limit to the query string or uri. Not small, but not big either.

https://stackoverflow.com/questions/812925/what-is-the-maximum-possible-length-of-a-query-string

How to represent the params in the query string for, say a list of ids? Turns out the “right” way is: http://our.api.com/Product?id=101404&id=7267261

https://stackoverflow.com/questions/2602043/rest-api-best-practice-how-to-accept-list-of-parameter-values-as-input

The URI gets a bit too long… hard to debug. So… can I send a GET request with a body? Turns out it is possible. My flask app seems to like it, though I had a hard time making that happen with AWS API Gateway and Lambda.

I did some more searches related to using GET with body. It turns out there is a split in opinions. Technically it’s doable, but that’s not what people expect things to work.

https://stackoverflow.com/questions/978061/http-get-with-request-body

For now I take the easy way to use POST with body for multiple params request (possibly a list of 10,000 ids). Sorry to REST that I failed the test.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s