Ntb\RestAPI\NestedResourceRestController
The nested resource controller can help you to avoid some boilerplate in nested resources in you rest api.
If you have a resource `user` and the endpoint `/users` then a nested resource could be the friends of a specific
user. `/users/1/friends` is a possible endpoint for that. In every method you first need to check if the user with the
id 1 is available in the system.
The friends controller can extend the nested resource rest controller and is now able to handle request in an easier
way.
- Author: Christian Blank <c.blank@notthatbad.net>
Synopsis
class NestedResourceRestController
extends BaseRestController
{
- // members
- protected static string $no_id_message = "No id provided.";
- protected static integer $no_id_error = 404;
- // methods
- public final array beforeCallActionHandler()
- protected abstract mixed getRootResource()
- // Inherited methods from BaseRestController
- public void init()
- public null head()
- protected HTMLText|SS_HTTPResponse handleAction()
- protected bool isAuthenticated()
- protected bool isAdmin()
- protected SS_HTTPResponse addCORSHeaders()
- protected Member currentUser()
Hierarchy
Extends
Tasks
Line | Task |
---|---|
165 | body could be an exception; check it before the response is generated |
Members
protected
- $no_id_error — int
- $no_id_message — string
Methods
protected
- getRootResource() — The result of this method will be injected in all method calls in the controller.
public
- beforeCallActionHandler() — Get called by the action handler of BaseRestController. Tries to fetch the root resource.
Inherited from Ntb\RestAPI\BaseRestController
protected
- addCORSHeaders()
- currentUser() — Return the current user from the request.
- handleAction() — handleAction implementation for rest controllers. This handles the requested action differently then the standard implementation.
- isAdmin() — Check if the user has admin privileges.
- isAuthenticated() — Check, if the request is authenticated.