acidjazz / metapi
Laravel API 辅助工具
v2.3.0
2024-04-25 05:59 UTC
Requires
- php: ^8.1
- ext-json: *
- illuminate/support: 9.*|10.*|11.*
- jasongrimes/paginator: ^1.0
Requires (Dev)
- mockery/mockery: ^1.4.4
- orchestra/testbench: ^7.0|^8.0
- phpunit/phpunit: ^9.5|^10.4
- dev-master
- v2.3.0
- v2.2.1
- v2.2.0
- v2.1.8
- v2.1.7
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.9
- v1.1.8
- 1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
This package is auto-updated.
Last update: 2024-09-25 06:51:47 UTC
README
拥有自己的端点
metapi 的主要目的是确保您的端点响应一致性。通过使用内置辅助函数如 ->option()...->verify
、->render()
、->success()
和 ->error()
,它们将共享相同的标准化输出,反映可用的选项、提供的参数和结果。
Dracula 暗色主题与 laravel-debugbar
功能
- 端点基准测试
- Laravel 验证包装器,反映要求
- 支持 JSON 和 JSONP
- 通过 jsoneditor 进行交互式树浏览和搜索
- 支持 Dracula 暗色主题,与 laravel-debugbar 配对
安装
使用 composer 安装 metapi
composer require acidjazz/metapi
添加特性
(推荐在
app/Http/Controllers/Controller.php
中添加)
<?php use acidjazz\metapi\MetApi; class Controller { use Metapi;
示例
<?php namespace App\Http\Controllers; use acidjazz\metapi\MetApi; class OrgController extends Controller { use MetApi; /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $this ->option('approved', 'nullable|boolean'); ->option('type', 'nullable|in:this,that'); ->verify(); ... $this->render($results);
GET /endpoint?approved=1
{ "benchmark": 0.011060953140258789, "query": { "defaults": [], "options": { "approved": "nullable|boolean", "type": "nullable|in:this,that" }, "params": { "approved": "1" }, "combined": { "approved": "1" } }, "data": [ {
GET /endpoint?callback=bob
bob({ "benchmark": 0.011017084121704102, "query": { "defaults": [], "options": { "approved": "nullable|boolean", "type": "nullable|in:this,that" }, "params": [], "combined": [] }, "data": [ {
将 自定义属性 添加到验证中。
public function send(Request $request) { $this->option('contact.email', 'required|email', [], 'Email Address') ->option('contact.name', 'required|string', [], 'Firstname') ->option('contact.surname', 'required|string', [], 'Lastname') ->verify(); ... $this->render($results); }
POST /send
{ "status": "error", "errors": [ { "status": 400, "message": "contact.email", "detail": "Email Address is a required field." }, { "status": 400, "message": "contact.name", "detail": "Firstname is a required field." }, { "status": 400, "message": "contact.surname", "detail": "Lastname is a required field." } ] }