koiiiey / api
Laravel REST API
dev-master
2020-11-30 12:32 UTC
This package is auto-updated.
Last update: 2024-09-29 04:37:13 UTC
README
认证令牌头 Authorization: Bearer {api_token}
认证API
登录
- 方法 post
- url /api/v1/auth/login
- 参数 email, password
- 返回 {api_token: '您的API令牌'}
注册
- 方法 post
- url /api/v1/auth/register
- 参数 email, name, password, password_confirmation
- 返回 {api_token: '您的API令牌'}
社交
- 方法 post
- url /api/v1/auth/social/{social_provider_name}
- 参数 client_id, code
- 返回 {api_token: '您的API令牌'}
获取当前用户
- 方法 get
- url /api/v1/auth/current
- 参数 with
- 返回 {user json}
实体API
获取实体分页器
- 方法 get
- url /api/v1/{entity_class_basename}
- 参数 filter, with, scope, per_page, page
- 返回 {total: 1,per_page: 30,current_page: 1,last_page: 1,next_page_url: null,prev_page_url: null,from: 1,to: 1,data: []}
创建实体
- 方法 post
- url /api/v1/{entity_class_basename}
- 参数 entity_attributes
- 返回 {created entity json}
==
示例:{a: 1, b: 2, c: {v: 5, n:6}} <-- 这里C是模型中的关联
获取单个实体
- 方法 get
- url /api/v1/{entity_class_basename}/{id}
- 参数 with
- 返回 {entity json}
更新实体
- 方法 put
- url /api/v1/{entity_class_basename}/{id}
- 参数 entity_attributes
- 返回 {updated entity json}
删除实体
- 方法 delete
- url /api/v1/{entity_class_basename}/{id}
- 返回空JSON对象 {}
关系API
获取实体关系
- 方法 get
- url /api/v1/{parent_class_basename}/{id}/{relation_name}
- 参数 filter, with, scope
- 返回 {relation json} 对象,对于一对一关系是对象,对于多对多关系是数组
创建相关实体
- 方法 post
- url /api/v1/{parent_class_basename}/{id}/{relation_name}
- 参数 entity_attributes
- 返回 {created entity json}
获取单个相关实体
- 方法 get
- url /api/v1/{parent_class_basename}/{id}/{relation_name}/{id}
- 参数 with
- 返回 {entity json}
更新相关实体
- 方法 put
- url /api/v1/{parent_class_basename}/{id}/{relation_name}/{id}
- 参数 entity_attributes
- 返回 {updated entity json}
删除相关实体
- 方法 delete
- url /api/v1/{parent_class_basename}/{id}/{relation_name}/{id}
- 返回空JSON对象 {}
============================
静态方法调用
示例:/api/v1/{entity_class_basename}/call/{method_name}/{params}
** 安装 **
- composer require koiiiey/api
- 在 config/app.php 中
- providers => [ Koiiiey\Api\ApiServiceProvider::class, ]
- 运行 php artisan vendor:publish --tag=guestFile 将会将 Guest.php 模型复制到 /app/ 目录。 \App\Guest 是用于未授权用户的类。
- 通过 [https://laravel.net.cn/docs/5.6/authorization] 配置您的认证