I am writing an API and want to follow the REST approach. As far as I understand, if I want API users to update certain records, a type query should be supported . Of course, they do not , and they will need to transfer new data, and my question is how to do this (in my particular case, only updating some fields of the specified record, but this is not so relevant here). There are two approaches that I can think of: including data in the request body (using curl:) or in the query string (using curl:) .PUT http://server/specific_resourceGETcurl -X PUT -d "key=value" http://server/specific_resourcecurl -X PUT http://server/specific_resource?key=value
Unfortunately, regardless of the approach I take, it seems very difficult to get the data provided. The problem is that PHP really fully understands two HTTP methods: GETand POST, PUTit is believed to upload files . If I include data in the body, then the only way to access it is through a callfopen('php://input') . For example, http_get_request_body()does not provide data. Similarly, information cannot be found in the supergalactic $_REQUEST. If I do not want to process the unprocessed request body with fopen('php://input'), then it seems that I should send the data as parameters of the query string, since the data will be displayed as elements of a superglobal (t211> superglobal (as well $_REQUEST).
I specifically use CakePHP and it seems to populate an array of formarrays paramsin my controller method if the request was POST . Query string parameters are placed in the array params, urlregardless of the query method, if used in the request URL. No wonder I'm not the only one who came across this.
What solution would you suggest? Process input stream? Use query string parameters? Just forget the verb PUTand use POSTinstead?
source
share