JSON Responses Structure
200 OK response
data array key as the parent key plus the actual response as an array
example of a single key returned
key in the data array should be with underscores
return [
'data' => [
'loan_parent' => $loanParent
],
'errors' => [],
'message' => 'Loan parent get successfully'
];404 Not Found
data array key response as an array is empty
errors array with technical error
message user-friendly message of error
key in the data array should be with underscores
$response = [
'data' => [
'loan_parent' => []
],
'message' => $exceptionMessage,
'errors' => [$exceptionMessage],
];
return response()->json($response, Response::HTTP_NOT_FOUND);Last updated