artyuum / symfony-jsend-response
JSendResponse component for HttpFoundation based applications (Symfony, Silex, Laravel, Drupal, etc.). It follows the JSend specification, allowing you to give consistent JSON responses to your users.
Installs: 27 084
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- symfony/http-foundation: ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.5
Replaces
- junker/symfony-jsend-response: <= 0.3.1
This package is auto-updated.
Last update: 2024-10-22 11:52:14 UTC
README
JSendResponse component for HttpFoundation based applications (Symfony, Silex, Laravel, Drupal, etc.). It follows the JSend specification, allowing you to give consistent JSON responses to your users.
Note: This repository is a maintened fork of Junker/JSendResponse. See the releases page for modification history.
Requirements
- PHP ^7.4 || ^8.0
- Symfony ^5.0 || ^6.0 || ^7.0
Installation
The best way to install JSendResponse is to use a Composer:
composer require artyuum/symfony-jsend-response
Examples
use Junker\JSendResponse\JSendResponse; use Junker\JSendResponse\JSendSuccessResponse; use Junker\JSendResponse\JSendFailResponse; use Junker\JSendResponse\JSendErrorResponse; class AppController { ... $data = ['id' => 50, 'name' => 'Waldemar']; $message = 'Error, total error!'; $code = 5; return new JSendResponse(JSendResponse::STATUS_SUCCESS, $data); // or return new JSendResponse(JSendResponse::STATUS_FAIL, $data); // or return new JSendResponse(JSendResponse::STATUS_ERROR, NULL, $message); // or return new JSendResponse(JSendResponse::STATUS_ERROR, $data, $message, $code); // or return new JSendSuccessResponse($data); // or return new JSendFailResponse($data); // or return new JSendErrorResponse($message); // or return new JSendErrorResponse($message, $code, $data); }
Contributing
If you'd like to contribute, please fork the repository and make changes as you'd like. Be sure to follow the same coding style & naming used in this library to produce a consistent code.