aedart / athenaeum-http-api
基于Json的API实用工具
8.10.0
2024-09-23 07:54 UTC
Requires
- php: ^8.2
- aedart/athenaeum-contracts: ^8.10
- aedart/athenaeum-etags: ^8.10
- aedart/athenaeum-support: ^8.10
- aedart/athenaeum-validation: ^8.10
- illuminate/http: ^v11.23.5
- shrikeh/teapot: ^2.3.1
Suggests
- laravel/framework: Required if you want to make use of API Request abstractions
- dev-main
- 8.10.0
- 8.9.0
- 8.8.0
- 8.7.0
- 8.6.0
- 8.5.0
- 8.4.0
- 8.3.0
- 8.2.0
- 8.1.0
- 8.0.0
- 7.33.0
- 7.32.0
- 7.31.0
- 7.30.1
- 7.30.0
- 7.29.0
- 7.28.0
- 7.27.0
- 7.26.0
- 7.25.0
- 7.24.0
- 7.23.0
- 7.22.1
- 7.22.0
- 7.21.0
- 7.20.0
- 7.19.0
- 7.18.1
- 7.18.0
- 7.17.0
- 7.16.0
- 7.15.0
- 7.14.0
- 7.13.0
- 7.12.0
- 7.11.3
- 7.11.2
- 7.11.1
- 7.11.0
- 7.10.1
- 7.10.0
- 7.9.1
- 7.9.0
- 7.8.0
- 7.7.2
- 7.7.1
- 7.7.0
- 7.6.0
- 7.5.0
- 7.4.0
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.1
- 7.0.0
- 7.0.0-alpha.1
- 6.8.1
- 6.8.0
- 6.7.0
- 6.6.0
- 6.5.2
- 6.5.1
- 6.5.0
This package is auto-updated.
Last update: 2024-09-23 07:55:58 UTC
README
意见性的实用工具,用于帮助你塑造和格式化API,使用Laravel的API资源。
示例
以下示例展示了一个用于Eloquent User模型的“API资源”。
use Aedart\Http\Api\Resources\ApiResource; use Illuminate\Http\Request; class UserResource extends ApiResource { public function formatPayload(Request $request): array { return $this->withTimestamps([ 'id' => $this->getResourceKey(), 'name' => $this->name, 'roles' => $this->belongsToManyReference('roles') ->withLabel('name') ->withSelfLink() ->withResourceType(); ]); } public function type(): string { return 'user'; } }
当返回单个用户的响应时,将输出以下JSON
{ "data": { "id": 34, "name": "Retta Altenwerth Jr.", "created_at": "2022-10-21T14:51:43+00:00", "updated_at": "2022-10-21T14:51:43+00:00", "roles": [ { "id": 23, "name": "Machine Operator", "type": "role", "self": "https:///roles/23" }, { "id": 56, "name": "File Clerk", "type": "role", "self": "https:///roles/56" } ] }, "meta": { "type": "user", "self": "https:///users/34" } }
文档
请阅读官方文档以获取更多信息。
仓库
单仓库位于github.com/aedart/athenaeum
版本控制
此包遵循语义版本控制2.0.0
许可证
BSD-3-Clause,请阅读此包中包含的LICENSE文件