Aplus Framework Docs

ResourceInterface
in

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 RouteCollection::resource().

Tags
see
https://developer.mozilla.org/en-US/docs/Glossary/REST

Table of Contents

create()  : mixed
Handles a POST request for /.
delete()  : mixed
Handles a DELETE request for /$id.
index()  : mixed
Handles a GET request for /.
replace()  : mixed
Handles a PUT request for /$id.
show()  : mixed
Handles a GET request for /$id.
update()  : mixed
Handles a PATCH request for /$id.

Methods

create()

Handles a POST request for /.

public create() : mixed

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.

Tags
see
Method::POST
see
ResourceInterface::show()
see
Status::BAD_REQUEST
see
Status::CREATED
see
ResponseHeader::LOCATION
Return values
mixed

delete()

Handles a DELETE request for /$id.

public delete(string $id) : mixed

Common usage: Delete an item based on the $id. On success, return a 204 (No Content) status code.

Parameters
$id : string
Tags
see
Method::DELETE
see
Status::NO_CONTENT
Return values
mixed

index()

Handles a GET request for /.

public index() : mixed

Common usage: Show a list of paginated items.

Tags
see
Method::GET
Return values
mixed

replace()

Handles a PUT request for /$id.

public replace(string $id) : mixed

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.

Parameters
$id : string
Tags
see
Method::PUT
see
ResourceInterface::show()
see
Status::BAD_REQUEST
see
Status::OK
see
ResponseHeader::LOCATION
Return values
mixed

show()

Handles a GET request for /$id.

public show(string $id) : mixed

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.

Parameters
$id : string
Tags
see
Method::GET
see
Status::NOT_FOUND
see
Status::OK
Return values
mixed

update()

Handles a PATCH request for /$id.

public update(string $id) : mixed

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.

Parameters
$id : string
Tags
see
Method::PATCH
see
ResourceInterface::show()
see
Status::BAD_REQUEST
see
Status::OK
see
ResponseHeader::LOCATION
Return values
mixed

Search results