Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http POST with Content-type: application/json #57

Open
novotnyj opened this issue Feb 26, 2015 · 9 comments
Open

Http POST with Content-type: application/json #57

novotnyj opened this issue Feb 26, 2015 · 9 comments

Comments

@novotnyj
Copy link

Request post attribute is currently filled with data from $_POST array. Would it be possible to set it like this
Nette\Utils\Json::decode(file_get_contents('php://input'), true); when method is POST and Content-type is application/json?

@fprochazka
Copy link
Contributor

I don't think it should be on by default. But an option, maybe?

@JanTvrdik
Copy link
Contributor

👍 on built-in support for application/json. I'm however not sure what's the best way to do it.

@novotnyj
Copy link
Author

@fprochazka Why do you think it shouldn't be on by default?
Or maybe other solution would be to add a new method to Request class - getJSON. It would be more general and usable for other request methods (PUT,...).

@fprochazka
Copy link
Contributor

I wouldn't like having it in $post of Http\Request. But I guess it wouldn't break anything.. right?
Maybe having it auto decode and set as $post of Application\Request in router layer, would be better?

@JanTvrdik
Copy link
Contributor

Adding getJson() to Http\Request is an "ok but conservative" way to do it. The question is whether we want to be smart about it.

One option would be to add general getBody() which would return getRawBody() parsed according to current Content-Type (with default support for JSON, XML and FormData)

@enumag
Copy link
Contributor

enumag commented Feb 26, 2015

@JanTvrdik And how should we add support for custom types? Don't forget that Http\Request should not be a service in the future.

@JanTvrdik
Copy link
Contributor

@enumag Remember that Http\Request is only a dummy value object. The actual data parsing would be done in Http\RequestFactory.

@JanTvrdik
Copy link
Contributor

Does anybody feel like writing a prototype?

@novotnyj
Copy link
Author

I have made a getJSON method draft: novotnyj/http@0e68551

JanTvrdik added a commit to JanTvrdik/nette-http that referenced this issue Feb 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants