(Thanks to Dustin Chabrowski for writing this FAQ entry!)
The problem
TL;DR
- HTTP PUT request for
updateAction
- payload (formatted as JSON) gets ignored
- the object is created by the identifier in the URI, not by http payload
-
updateAction()
takes the existing object for upgrade, therefore no changes happen
In a RESTful service, an already existing object should be updated. While all other HTTP methods and
their respective actions work out of the box when the Flow RestController
is used, the
updateAction()
seems to only create the object from the given URI (e.g. http://example.com/authors/123-12132-12321), but it does not create the new object from the request payload data.
Example
Controller:
/**
* @param \Acme\Project\Domain\Model\Author $author
* @throws \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException
*/
public function updateAction(Author $author) {
//$author is the existing object with old properties
$this->authorRepository->update($author);
$this->response->setStatus(200);
}
Routes.yaml
- name: 'Authors'
uriPattern: 'authors<AuthorSubroutes>(.{@format})'
defaults:
@package: 'Acme.Project'
@controller: Author
subRoutes:
AuthorSubroutes:
package: 'Acme.Project'
suffix: Author
Routes.Author.yaml
- name: 'Author Update URI'
uriPattern: '/{author}'
defaults:
'@action': 'update'
httpMethods:
- PUT
The solution
Replace the uriPattern in the subroute for PUT with /{author.__identity}
.
By doing so, the object gets created with the data from the http request payload.
Routes.Author.yaml
- name: 'Author Update URI'
uriPattern: '/{author.__identity}'
defaults:
'@action': 'update'
httpMethods:
- PUT