Jet\RESTServer_Backend

The backend interface of the Jet\RESTServer.

Method Overview

Method Meaning of
public init(
) : void
Initialization of the REST server itself. For example, it does things like debugging switches to JSON mode, sets up error pages, or performs other necessary operations.
public getRequestMethod(
) : string
Specifies the method of the request (whether it is post, get, put, delete, ...)
public getRequestData(
) : array
Returns the data from the request body (e.g. during a post request) from JSON converted to the associated field.

Validation whether the request body exists and whether it is JSON is performed automatically.
public getHttpRequestHeader(
string $header,
string $default_value=''
) : string
Returns the value of the specified HTTP header of the request, or the default value if this header is missing from the request.
public responseData(
mixed $data
) : void
General sending of arbitrary data - e.g. data of a certain entity (for example, an article) after a successful get request.
public responseOK(
string $message=''
) : void
Simple answer OK - only with a certain message, but no additional data.
public handleNotAuthorized(
) : void
A generic "you're not authorised to do that" response.
public responseError(
string|int $code,
mixed $data=null
) : void
A general error response with some code and optionally with error data specifying the nature of the error.
public responseValidationError(
array $errors
) : void
Input data validation error.
The error messages in the field must be serializable to JSON.
This can be for example an instance of Jet\Form_ValidationError.
public responseUnknownItem(
string|array $id
) : void
General answer unknown item/unknown items. The $id parameter specifies which item is unknown / which items are unknown.
public responseBadRequest(
) : void
General answer "wrong request".
public handleDataPagination(
DataModel_Fetch_Instances $data
) : Data_Paginator
Based on the get parameters (for example, depending on the specific implementation), it will process the pagination of the data list and return the set pager.
public handleOrderBy(
DataModel_Fetch_Instances $data,
array $sort_items_map
) : DataModel_Fetch_Instances
Based on the get parameters (for example - it depends on the specific implementation), it serves the sorting of the list of data. The $sort_items_map parameter is an associated array that specifies which parameter (e.g. get) will sort which data column. For example: public function list_Action(): void
    
{
        
$this->responseData(
            
$this->handleDataPagination(
                
$this->handleOrderBy(
                    
Content_Article::getList(),
                    [
                        
'title'     => 'article_localized.title',
                        
'date_time' => 'article.date_time'
                    
]
                )
            )
        );
    }
Previous chapter
Jet\RESTServer
Next chapter
Jet\RESTServer_Backend_Default