ResourceInterface interface
Framework\Routing\ResourceInterface
Interface ResourceInterface.
The interface for data management via RESTful APIs
using all correct HTTP methods to manage a resource.
Note: If a resource needs more than one parameter to get URL path information
provided by placeholders, in addition to $id, do not implement this interface.
But this interface can be a reference because its method names are used in
{@see RouteCollection::resource()}.
Defined in libraries/routing/src/ResourceInterface.php
Methods #
- create()
- Handles a POST request for /.
- delete()
- Handles a DELETE request for /$id.
- index()
- Handles a GET request for /.
- replace()
- Handles a PUT request for /$id.
- show()
- Handles a GET request for /$id.
- update()
- Handles a PATCH request for /$id.
create()
Handles a POST request for /.
Common usage: Try to create an item. On success, set the Location header to
the 'show' method URL and return a 201 (Created) status code. On fail, return
a 400 (Bad Request) status code and list the error messages in the body.
delete()
Handles a DELETE request for /$id.
Common usage: Delete an item based on the $id. On success, return a 204
(No Content) status code.
- string $id
index()
Handles a GET request for /.
Common usage: Show a list of paginated items.
replace()
Handles a PUT request for /$id.
Common usage: Try to replace an item based on the $id. On success return a 200
(OK) status code and set the Location header to the 'show' method URL. On
fail, return a 400 (Bad Request) with the validation errors in the body.
Note: The HTTP PUT method requires an entire resource to be updated. E.g.
all fields in a database table row should be updated/replaced.
- string $id
show()
Handles a GET request for /$id.
Common usage: Show a specific item, based on the $id, in the body. If the item
does not exist, return an 404 (Not Found) status code.
- string $id
update()
Handles a PATCH request for /$id.
Common usage: Try to update an item based on the $id. On success return a 200
(OK) status code and set the Location header to the 'show' method URL. On
fail, return a 400 (Bad Request) with the validation errors in the body.
Note: The HTTP PATCH method allow items to be updated by parts. E.g.
it is possible to update only one, or more, fields in a database table
row.
- string $id