pickmap/response

A Responder for all REST FULL api outputs

0.2.0 2023-09-04 10:04 UTC

This package is not auto-updated.

Last update: 2024-09-30 14:57:01 UTC


README

Most of the time we need the same output structure for all REST FULL API responses.

In this package, based on the rules of the link below (jsend), you can send your response in a standard way https://github.com/omniti-labs/jsend

How to use this package ?

step #1

Install the package with the following command

composer require pickmap/response

step #3

Go to this path in your Laravel project app/Exceptions/Handler.php and put this codes

use Pickmap\Responder\Res;
public  function  render($request, Throwable  $e)
{
	if ($e  instanceof  ModelNotFoundException)
	{
		return  Res::error('not found',null,404);
	}
	elseif ($e  instanceof  ValidationException)
	{
		return  Res::error($e->getMessage(),null,422);
	}
	
	return  parent::render($request, $e);
}

step #3

now you can use like this

Res::success($objectData);
Res::success($arrayData,201);
Res::error('create faild');
Res::error('new error',419);
Res::fail($data);
Res::response($status,$message,$data,$code);