$request
$request : \CodeIgniter\HTTP\IncomingRequest
Response trait.
Provides common, more readable, methods to provide consistent HTTP responses under a variety of common situations when working as an API.
respond(array|string|null $data = null, integer $status = null, string $message = '') : mixed
Provides a single, simple method to return an API response, formatted to match the requested format, with proper content-type and status code.
array|string|null | $data | |
integer | $status | |
string | $message |
fail(string|array $messages, integer|null $status = 400, string|null $code = null, string $customMessage = '') : mixed
Used for generic failures that no custom methods exist for.
string|array | $messages | |
integer|null | $status | HTTP status code |
string|null | $code | Custom, API-specific, error code |
string | $customMessage |
failUnauthorized(string $description = 'Unauthorized', string $code = null, string $message = '') : mixed
Used when the client is either didn't send authorization information, or had bad authorization credentials. User is encouraged to try again with the proper information.
string | $description | |
string | $code | |
string | $message |
failResourceGone(string $description = 'Gone', string $code = null, string $message = '') : mixed
Use when a resource was previously deleted. This is different than Not Found, because here we know the data previously existed, but is now gone, where Not Found means we simply cannot find any information about it.
string | $description | |
string | $code | |
string | $message |
failServerError(string $description = 'Internal Server Error', string|null $code = null, string $message = '') : \CodeIgniter\HTTP\Response
Used when there is a server error.
string | $description | The error message to show the user. |
string|null | $code | A custom, API-specific, error code. |
string | $message | A custom "reason" message to return. |
The value of the Response's send() method.