| Fully Qualified Name: | CodeIgniter\API\ResponseTrait |
Response trait.
Provides common, more readable, methods to provide consistent HTTP responses under a variety of common situations when working as an API.
| 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 |
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
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
Used when a specified resource cannot be found.
| Parameter Name | Type | Description |
|---|---|---|
| $description | string | |
| $code | string | |
| $message | string |
Returns: mixed
Use when trying to create a new resource and it already exists.
| Parameter Name | Type | Description |
|---|---|---|
| $description | string | |
| $code | string | |
| $message | string |
Returns: 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.
| Parameter Name | Type | Description |
|---|---|---|
| $description | string | |
| $code | string | |
| $message | string |
Returns: mixed
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.
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
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
Used when the data provided by the client cannot be validated.
| Parameter Name | Type | Description |
|---|---|---|
| $description | string | |
| $code | string | |
| $message | string |
Returns: mixed
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
Used after successfully creating a new resource.
| Parameter Name | Type | Description |
|---|---|---|
| $data | mixed | Data. |
| $message | string | Message. |
Returns: mixed
Used after a resource has been successfully deleted.
| Parameter Name | Type | Description |
|---|---|---|
| $data | mixed | Data. |
| $message | string | Message. |
Returns: mixed
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
Used after a resource has been successfully updated.
| Parameter Name | Type | Description |
|---|---|---|
| $data | mixed | Data. |
| $message | string | Message. |
Returns: mixed
Sets the format the response should be in.
| Parameter Name | Type | Description |
|---|---|---|
| $format | string |
Returns: $this