We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

API getPost content negotiation

right now I'm sending json requests to my API, and I want to be able to get the POST data send in request, with $request->getPost(). So I could plug any content type, json, etc..

I tried to override the request service with a custom one (JSONRequest) but I don't know when to override it, it I do it beforeExecuteRoute it does not work properly. Any thoughts on how to accomplish this?



43.9k

Hi

with Phalcon\Http\Request you can use "getJsonRawBody ([unknown $associative])"

edited May '15

Hi @le51 I'm aware of that but I was looking for something more object oriented. In fact, what I would like to have is a Request object with all the utilities this one provides and transparent content type management. My problem here is that, even If I create an adapter for the Json request, (kind of https://github.com/cmoore4/phalcon-rest/blob/develop/responses/JSONResponse.php) I don't know how to plug it (I'm using a normal http request except for certain routes). I tried with the beforeExecuteRoute, but at that moment the default request is already set.