Essential CRUD

For simplicity, I have numbered each of the rows. The first and second items represent the read part of CRUD.

The first item, which is a GET call to the plural form of the model name, is rather simple; it displays all of the items. Sometimes, this is called a list to differentiate it from the read of a single record. Adding alist would thus expand the acronym to CRUDL. They could be paginated or require authorization.

The second item, also a GET call, adds the ID of the model to the end of the URL, displaying a single model with that corresponding ID. This could also require authentication but not paging.

The third item represents the create part of CRUD. It uses the POST verb to create a new model. Note that the URL format is the same as the first item; this demonstrates the importance of the verb to distinguish between the actions.

The fourth, fifth, and sixth items use the new HTTP verbs that were not supported by all browsers. Whether or not the verbs are supported, JavaScript libraries and frameworks, such as jQuery, will send the verb in a way that Laravel can properly handle.

The fourth item is the update part of CRUD and updates the model using the PUT verb. Note that it has the same URL format as the second, as it needs to know which model to update. It is also idempotent, which means that the entire model must be updated.

The fifth item is similar to the fourth item; it updates the model, but uses the PATCH verb. This is used to indicate that the model will be partially modified, which means that one or more of the model’s attributes have to be changed.

The sixth item deletes a single model and thus requires the model’s ID, using the self-explanatoryDELETE verb.