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

Allow empty body for POST and PUT requests #781

Closed
kbsali opened this issue Sep 30, 2016 · 8 comments
Closed

Allow empty body for POST and PUT requests #781

kbsali opened this issue Sep 30, 2016 · 8 comments

Comments

@kbsali
Copy link

kbsali commented Sep 30, 2016

Right now it is not possible to POST or PUT requests without specifying at least an empty object.
While this is correct for most of the use case, we've had to add a listener to bypass this for new PUT entry points we are creating which "carries" the change to be applied to our object.
eg. PUT /api/blog_posts/[id]/publish

Here is a "serious" source showing that this is perfectly fine : http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0276.html :)

Do you agree? If you do, I will try to submit a PR asap, otherwise i'll live with our custom listener...

@teohhanhui
Copy link
Contributor

teohhanhui commented Sep 30, 2016

I think your solution is fine because we're talking about custom operations anyway.

Yes, I myself have run into this problem too when I implemented a POST /products?copyOf=/products/1 to clone a resource (sending empty body).

@teohhanhui
Copy link
Contributor

teohhanhui commented Sep 30, 2016

But it'd be good if we can take care of this automatically, i.e. don't try to deserialize if body is empty.

Still, what if a media type attaches some meaning to an empty body?

@kbsali
Copy link
Author

kbsali commented Sep 30, 2016

@teohhanhui so do you think a PR would be acceptable for this? :)

@teohhanhui
Copy link
Contributor

Yes please.

@teohhanhui
Copy link
Contributor

Just adding a check here should do:

$request->attributes->set(
'data',
$this->serializer->deserialize(
$request->getContent(), $attributes['resource_class'], $format, $context
)
);

@kbsali
Copy link
Author

kbsali commented Dec 9, 2016

closing as this has been apparently discarded!
too bad... i don't understand why it was ok to do this to start with, and once a PR was submitted, it was discarded. :-(

@kbsali kbsali closed this as completed Dec 9, 2016
@dunglas
Copy link
Member

dunglas commented Dec 9, 2016

@kbsali I'm still ok to merge it, we just need to finish it.

@teohhanhui
Copy link
Contributor

teohhanhui commented Jan 20, 2017

I suggest decorating the listener, like https://github.com/api-platform/docs/blob/e698aef1b147e94190dc189471b1c4b093545856/core/form-data.md

(It's already possible to cleanly decorate event listeners since symfony/symfony#20207 - see discussion in symfony/symfony#19697. The documentation needs to be updated to reflect that.)

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

3 participants