RESTful APIs in Laravel
The list of RESTful API requests handled by the RESTful API are as follows:
HTTP VERB | Function | UR | |
---|---|---|---|
1 | GET |
This lists all accommodations | /accommodations |
2 | GET |
This shows (reads) a single accommodation | /accommodations/{id} |
3 | POST |
This creates a new accommodation | /accommodations |
4 | PUT |
This entirely modifies (updates) an accommodation | /accommodations/{id} |
5 | PATCH |
This partially modifies (updates) an accommodation | /accommodations/{id} |
6 | DELETE |
This deletes an accommodation | /accommodations/{id} |
Most RESTful API best practices suggest using the plural form of the model name. Laravel’s documentation uses the singular format. Most practices agree that consistent plural naming, that is,/accommodations/{id}
refers to a single accommodation and /accommodations
refers to more than one accommodation, both using the plural form are preferred over a mixed, but grammatically correct /accommodation/{id}
(singular form) and /accommodations
(plural form).