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

Comments

Projects
None yet
4 participants
@novotnyj

novotnyj commented Feb 26, 2015

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

This comment has been minimized.

Contributor

fprochazka commented Feb 26, 2015

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

@JanTvrdik

This comment has been minimized.

Contributor

JanTvrdik commented Feb 26, 2015

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

@novotnyj

This comment has been minimized.

novotnyj commented Feb 26, 2015

@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

This comment has been minimized.

Contributor

fprochazka commented Feb 26, 2015

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

This comment has been minimized.

Contributor

JanTvrdik commented Feb 26, 2015

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

JanTvrdik commented Feb 26, 2015

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

@JanTvrdik

This comment has been minimized.

Contributor

JanTvrdik commented Feb 26, 2015

Does anybody feel like writing a prototype?

@novotnyj

This comment has been minimized.

novotnyj commented Feb 26, 2015

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