Skip to content

Visapick-Team/responder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

About Responder

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

TypeDescriptionRequired KeysOptional Keys
successAll went well, and (usually) some data was returned.status, data
failThere was a problem with the data submitted, or some pre-condition of the API call wasn't satisfiedstatus, data
errorAn error occurred in processing the request, i.e. an exception was thrownstatus, messagecode, data

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);

About

A Responder for all restful api outputs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages