mpstr24/laravel-api-responses
Composer 安装命令:
composer require mpstr24/laravel-api-responses
包简介
Laravel package for formatted API responses.
README 文档
README
This package provides API response functions via a trait to help improve consistency of API response codes across your projects.
Features
- Pre-made functions of the most common API responses.
Installation
Install the package via Composer:
composer require mpstr24/laravel-api-responses
Usage/Examples
First add the trait to your controller.
use ApiResponseTrait;
All methods, except from "No Content" allow for a message and data to be returned. Custom messages also allow you to choose the status code.
Examples of each below.
Success - 200
public function success() { return $this->apiSuccess(); }
Created - 201
public function created() { return $this->apiCreated(); }
Accepted - 202
public function accepted() { return $this->apiAccepted(); }
No Content - 204
public function noContent() { return $this->apiNoContent(); }
Bad Request - 400
public function badRequest() { return $this->apiBadRequest(); }
Unauthorized - 401
public function unauthorized() { return $this->apiUnauthorized(); }
Forbidden - 403
public function forbidden() { return $this->apiForbidden(); }
Not Found - 404
public function notFound() { return $this->apiNotFound(); }
Teapot - 418
public function teapot() { return $this->apiTeapot(); }
Unprocessable - 422
public function unprocessable() { return $this->apiUnprocessable(); }
Too Many Requests - 429
public function tooManyRequests() { return $this->apiTooManyRequests(); }
Server Error - 500
public function serverError() { return $this->apiInternalServerError(); }
Custom response
public function apiCustomResponse() { return $this->apiCustom('Custom', null, 201); }
Roadmap
- Support for resources
- Expand into more helpful API features
- Larastan goals
- 5
- 6
- 7
- 8
- 9
License
统计信息
- 总下载量: 1.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-10