dyonis/symfony-api-response

Symfony API Response component

0.1.2 2024-02-25 23:53 UTC

This package is auto-updated.

Last update: 2024-10-26 01:50:47 UTC


README

Usage in controllers:

Success response

return (new ApiResponse())
  ->setData(['product' => $product])
  ->setMessage('Successfully saved');

Redirect response

return (new ApiResponse())
  ->apiRedirect('https://some.url', 302);

Error response

$response = new ApiResponse();
$response->addErrors(['Error 1', 'Error 2'])
$response->addError('Error 3');
$response->addError('Error 4', 'Field');

return $response