Jet\MVC_Controller_REST

This class is used as a basis for creating controllers of application modules that make up the REST API server. In the sample application, you can see examples of the REST API created in the form of Content.Articles.REST modules (a simple API for working with articles) and Content.Images.REST (a slightly more complex API for working with galleries and images).

Jet has a Jet\REST class to facilitate the creation of REST APIs. And the Jet\MVC_Controller_REST class is actually just a wrapper and bridge between the controller and the Jet\REST class.

Method Meaning of
public __construct(
MVC_Page_Content_Interface $content
)
The constructor calls the parent constructor, but also calls the REST::init() method;
public getRequestMethod(
): string
Distinguishes whether the request is a GET, POST, PUT, or DELETE request.

Alias for calling the REST::getRequestMethod() method;
public getRequestData(
): array
Returns the raw request data already converted from JSON to an array.

Alias for calling the REST::getRequestData() method;
public responseOK(
string $message = ''
): void
Sends a response notifying the success of the operation (e.g. save, delete, etc.)

Alias for calling the REST::responseOK( $message ) method;
public responseData(
mixed $data
): void
Sends the data as a reply. Can send anything that can be encoded into JSON.

Alias for calling the REST::responseData( $data ) method;
public handleNotAuthorized(
): void
Sends a notification that the operation was rejected due to not logging in or insufficient privileges.

Alias for calling the REST::handleNotAuthorized() method;
public responseError(
string|int $code,
mixed $data = null
): void
Returns an error message with the error code and contextual data about the error (error specifics).

Alias for calling the REST::responseError( $code, $data ) method;
public responseValidationError(
array $errors
): void
Returns a notification of an input validation error.

Alias for calling the REST::responseValidationError( $errors ) method;
public responseUnknownItem(
string|array $id
): void
Returns 404 - item not found.

Alias for calling the REST::responseUnknownItem( $id ) method;
public responseBadRequest(
): void
Returns a notification that the request is unintelligible.

Alias for calling the REST::responseBadRequest() method;
protected handleDataPagination(
DataModel_Fetch_Instances $data
): Data_Paginator
Method that handles pagination of item lists.

Alias for calling the REST::handleDataPagination( $data ) method;
protected handleOrderBy(
DataModel_Fetch_Instances $data,
array $sort_items_map
): DataModel_Fetch_Instances
A medoa that handles sorting lists of items.

Alias for calling the REST::handleOrderBy( $data, $sort_items_map ) method;
Previous chapter
Jet\MVC_Controller_Default
Next chapter
Microrouter