This section is deprecated. However, as of now, the Sylius E-Commerce project is still resorting to this configuration so you might want to check it out.
To display an edit form of a particular resource, change it or update it via API, you should use the updateAction action of your app.controller.book service.
Done! Now when you go to /books/5/edit, ResourceController will use the repository (app.repository.book) to find the book with id == 5. If found it will create the app_book form, and set the existing book as data.
Submitting the Form
You can use exactly the same route to handle the submit of the form and updating the book.
On submit, the update action with method PUT, will bind the request on the form, and if it is valid it will use the right manager to persist the resource. Then, by default it redirects to app_book_show to display the updated book, but like for creation of the resource - it's customizable.
When validation fails, it will simply render the form again, but with error messages.
Changing the Template
Just like for other actions, you can customize the template.
By default, there are two events dispatched during resource update, one before setting new data, the other after successful update. The pattern is always the same - {applicationName}.{resourceName}.pre/post_update. However, you can customize the last part of the event, to provide your own action name.
This way, you can listen to app.book.pre_customer_update and app.book.post_customer_update events. It's especially useful, when you use ResourceController:updateAction in more than one route.
[API] Returning resource or no content
Depending on your app approach it can be useful to return a changed object or only the 204 HTTP Code, which indicates that everything worked smoothly. Sylius, by default is returning the 204 HTTP Code, which indicates an empty response. If you would like to receive a whole object as a response you should set a return_content option to true.
The return_content flag is available for the applyStateMachineTransitionAction method as well. But these are the only ones which can be configured this way. It is worth noticing, that the applyStateMachineTransitionAction returns a default 200 HTTP Code response with a fully serialized object.