Response
in package
Standardized JSON response helper for API V1.
Returns JsonResponse objects that can be sent by the caller.
Table of Contents
Methods
- created() : JsonResponse
- Create created response (201).
- error() : JsonResponse
- Create error response.
- notFound() : JsonResponse
- Create not found response.
- send() : JsonResponse
- Create JSON response.
- success() : JsonResponse
- Create success response.
Methods
created()
Create created response (201).
public
static created(mixed $data) : JsonResponse
Parameters
- $data : mixed
-
Response data
Return values
JsonResponseerror()
Create error response.
public
static error(string $message[, int $status = 400 ]) : JsonResponse
Parameters
- $message : string
-
Error message
- $status : int = 400
-
HTTP status code (default 400)
Return values
JsonResponsenotFound()
Create not found response.
public
static notFound([string $message = 'Not found' ]) : JsonResponse
Parameters
- $message : string = 'Not found'
-
Error message (default: "Not found")
Return values
JsonResponsesend()
Create JSON response.
public
static send(int $status, mixed $data) : JsonResponse
Parameters
- $status : int
-
HTTP status code
- $data : mixed
-
Response data
Return values
JsonResponsesuccess()
Create success response.
public
static success(mixed $data[, int $status = 200 ]) : JsonResponse
Parameters
- $data : mixed
-
Response data
- $status : int = 200
-
HTTP status code (default 200)