Micheal Powers
Micheal Powers

Reputation: 61

Is there a size limit for HTTP GET requests with JSON bodies?

I'm calling a PHP REST API from an iOS app to retrieve data from my MySQL database. I wanted to know if there is a size limit on the amount of data I can receive via a HTTP GET request, given that it's serialized as JSON.

Upvotes: 3

Views: 13691

Answers (2)

Chiru
Chiru

Reputation: 4091

Is there a size limit for HTTP GET requests with JSON bodies?

No, there is no size limit in HTTP, but there might be a limit elsewhere.

HTTP response bodies may have an arbitrary size, though there are several other factors that might enforce a hard limit:

  • In your specific case, PHP itself. PHP has a configuration variable named memory_limit which imposes a limit for the PHP process.
  • Your physical memory. The problem with sending out JSON is that, unless you have a very special setup and are streaming the response, the entire JSON payload needs to be buffered in your server's memory (alongside the result rows from your query!).

In practice, memory_limit will be the first limit that you will hit. It's usually advisable to use LIMIT in your SQL queries and paginate the responses. Sending out over, say, 1 MiB of JSON is generally not a very good idea.

Upvotes: 4

Sophia
Sophia

Reputation: 46

I believe there are no size limitations with JSON requests. Any direct limitations, however, could be caused or set by the parsing of the request via the server. Therefore, it's possible to think that perhaps the MySQL DB itself may have some. Hope this helps!

Upvotes: 1

Related Questions