Editing Resources

This page covers the setup for PUT and PATCH requests to modify a resource via the Bakery package.

There are two distinct types of editing, based on the HTTP Method used in the request. PUT requests are holistic updates (overwrites), whilst PATCH requests are partial updates. Consequently, in a PUT request anything not specified will be overwritten or unset, whereas failing to set a property in a PATCH request will simply mean that property is not updated.

To enable PUT and PATCH requests, add put and patch into the enabled array on your model configuration.

Shared Functionality

Must functionality is shared between the PUT and PATCH requests, this is defined below. For differences see the Holistic Updates and Partial Updates sections of this page.

Validation

You can specify the validator configuration with a class which implements ProvidesBakeryValidationRules interface.

Security

Security configurations as per the Security documentation.

Modifier

You can specify a modifier configuration as a class which implements the ModifiesBakeryResource interface, this will be executed immediately before the model is saved.

Events

In addition to the global and model level events, you can specify events specific to this method/model combination. Do this by specifying a list of classes, all of which must conform to the BakeryEvent interface.

Holistic Updates (PUT)

You can specify information about the fields to be handled in a PUT request, these are specified in the fields configuration, with three child arrays.

You can choose to either explicitly define what you want to accept, or explicitly what you wish to not accept, these are one using the fields.accept and fields.reject arrays.

Additionally, because this is a holistic update, you can also specify which feels should be nullified if they are not specified, in the fields.nullify array.

Partial Updates (PATCH)

To specify which fields can be modified via a PATCH request you must specify models.{slug}.patch.fields array

Last updated

Was this helpful?