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.

1.2.0 2024-01-21 15:32 UTC

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.