I am facing a problem within a PHP Restful API ...
I am trying to GET some products informations (weight, process, price ...) by calling this API.
The problem is that the provided URI can contain a lot of characters because we are trying to make as less API calls as possible.
As you can understand, if we send a too long URI using HTTP GET method, I will surely finish with a 414 or 500 HTTP ERROR.
So how can we :
- Send an HTTP GET request to get informations having a long URI
- Stay RESTFUL (without using POST as if I refer to the Restful documentation -> That is the major issue)
Here is an example of a request :
http://<myWebsite>/rprocess/api/process/{"data":["FLY.DELeco.LOT100.DIM10x10.FACrv.SUPdemma.GRA350.PELbrv.VERss","FLY.DELnor.LOT500.DIM20x30.FACr.SUPcoubr.GRA300.PELbrv.VERss"]}
- As you can see, we send a JSON encoded string in the URI.
- This example works because we only try to get [process] informations for two products (we want to make a call with a lot more)
I have already searched for an answer on this problem but it looks like we can not stay restful in that case.
Here are the answers I have found:
- Use POST and add set headers to
X-HTTP-Method-Override: GET
- Increase the
url limit size
on the server (not recommended) - Split the GET requests in order not to reach the url length limit (that's not a good idea because the API can handle way more product at a time as we can actually send it ...)
I hope those informations can help you answer my question :)
Thank you for your help