承接 pickmap/response 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pickmap/response

最新稳定版本:0.2.0

Composer 安装命令:

composer require pickmap/response

包简介

A Responder for all REST FULL api outputs

README 文档

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

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

统计信息

  • 总下载量: 541
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-10