Interface ResponseTrait

Summary

Fully Qualified Name: CodeIgniter\API\ResponseTrait

Description

Response trait.

Provides common, more readable, methods to provide consistent HTTP responses under a variety of common situations when working as an API.

Methods

Name Description Defined By
fail() Used for generic failures that no custom methods exist for. ResponseTrait
failForbidden() Used when access is always denied to this resource and no amount of trying again will help. ResponseTrait
failNotFound() Used when a specified resource cannot be found. ResponseTrait
failResourceExists() Use when trying to create a new resource and it already exists. ResponseTrait
failResourceGone() 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. ResponseTrait
failServerError() Used when there is a server error. ResponseTrait
failTooManyRequests() Used when the user has made too many requests for the resource recently. ResponseTrait
failUnauthorized() 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. ResponseTrait
failValidationError() Used when the data provided by the client cannot be validated. ResponseTrait
respond() Provides a single, simple method to return an API response, formatted to match the requested format, with proper content-type and status code. ResponseTrait
respondCreated() Used after successfully creating a new resource. ResponseTrait
respondDeleted() Used after a resource has been successfully deleted. ResponseTrait
respondNoContent() Used after a command has been successfully executed but there is no meaningful reply to send back to the client. ResponseTrait
respondUpdated() Used after a resource has been successfully updated. ResponseTrait
setResponseFormat() Sets the format the response should be in. ResponseTrait

Method Details

fail()

Used for generic failures that no custom methods exist for.

Parameter Name Type Description
$messages string|array
$status int|null HTTP
$code string|null Custom,
$customMessage string

Returns: mixed

failForbidden()

Used when access is always denied to this resource and no amount of trying again will help.

Parameter Name Type Description
$description string
$code string
$message string

Returns: mixed

failNotFound()

Used when a specified resource cannot be found.

Parameter Name Type Description
$description string
$code string
$message string

Returns: mixed

failResourceExists()

Use when trying to create a new resource and it already exists.

Parameter Name Type Description
$description string
$code string
$message string

Returns: mixed

failResourceGone()

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.

Parameter Name Type Description
$description string
$code string
$message string

Returns: mixed

failServerError()

Used when there is a server error.

Parameter Name Type Description
$description string The
$code string|null A
$message string A

Returns: \Response The value of the Response's send() method.

failTooManyRequests()

Used when the user has made too many requests for the resource recently.

Parameter Name Type Description
$description string
$code string
$message string

Returns: mixed

failUnauthorized()

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.

Parameter Name Type Description
$description string
$code string
$message string

Returns: mixed

failValidationError()

Used when the data provided by the client cannot be validated.

Parameter Name Type Description
$description string
$code string
$message string

Returns: mixed

respond()

Provides a single, simple method to return an API response, formatted to match the requested format, with proper content-type and status code.

Parameter Name Type Description
$data array|string|null
$status int
$message string

Returns: mixed

respondCreated()

Used after successfully creating a new resource.

Parameter Name Type Description
$data mixed Data.
$message string Message.

Returns: mixed

respondDeleted()

Used after a resource has been successfully deleted.

Parameter Name Type Description
$data mixed Data.
$message string Message.

Returns: mixed

respondNoContent()

Used after a command has been successfully executed but there is no meaningful reply to send back to the client.

Parameter Name Type Description
$message string Message.

Returns: mixed

respondUpdated()

Used after a resource has been successfully updated.

Parameter Name Type Description
$data mixed Data.
$message string Message.

Returns: mixed

setResponseFormat()

Sets the format the response should be in.

Parameter Name Type Description
$format string

Returns: $this

Top