Fixing put action for proper PUT method handling. #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/5-automatic-route-generation_single-restful-controller.md
PUT - this action accepts PUT requests to the url /resources/{id} and updates a single resource for this type
PATCH - This action also accepts PATCH requests to the url /resources/{id} and is supposed to partially modify the resource or made custom updates.
So PUT is intended to update all fields of the entity at once, while PATCH could be used for updating subset of all fields.
Consider following scenario: we have a form with 3 fields - name, email, phone. All fields are required. If field is empty JS-frameworks often do not send it. User fill only first 2 fields (name, email) by mistake and send a PUT request to out REST API. We expect form validation to fail (since user omitted phone field). But if generated code switch request method from PUT to PATCH - request is passed but with undesired result - we now have name and email updated in our entity. Symphony code for handling form request ($form->handleRequest) detects PATCH method. For non-PATCH methods missing fields are cleared, for PATCH - they are filled with values from database-entity.
Commit where this functionality was added https://github.com/symfony/symfony/pull/7849/files
If you want, we could implement parameter for controlling this behavior (either switching PUT to PATCH or not).