krzysztof-moskalik/api-client-bundle
最新稳定版本:1.1.0
Composer 安装命令:
composer require krzysztof-moskalik/api-client-bundle
包简介
Bridge for KrzysztofMoskalik\ApiClient
README 文档
README
Note: Project under construction!
Not All features are implemented yet!
This Project is a bridge for ApiClient (krzysztof-moskalik/api-client).
Installation
Install this package via composer:
composer require krzysztof-moskalik/api-client-bundle'
Then register bundle in config/bundles.php:
KrzysztofMoskalik\ApiClientBundle\ApiClientBundle::class => ['all' => true],
Place configuration in config\packages\api_client.yaml file.
Configuration Reference
api_client:
api:
my_api:
baseUrl: https://my-api.example.com // API host
auth: // remove if Api has no auth
method: basic // basic and token are supported for now
username: test-user // username for `basic` auth
password: test-user-password // password for `basic` auth
token: bG9yZW0gaXBzdW0= // token for `token` auth
header: X-Auth-Token // header for containing token auth
extraHeaders: // extra headers for all requests
Accept: application/json
resources: // resources in your api
users:
path: /v1/users // path to resource
model: App\Model\User // model used to store and fetch data
api: my_api // api related to this resource
endpoints: // endpoints in this resource
getAll: // endpoint label
requestDataPath: 'user' // path to data in request body (optional)
responseDataPath: 'data' // path to data in respons body (optional)
type: create // endpoint type (create | get | getAll | update | updatePartial | delete)
Usage
Just simply inject KrzysztofMoskalik\ApiClient\Client class into your service.
Then you can get a repository for your model:
$repository = $this->client->getRepository(User::class);
And then call some action (which should be configured beforehand):
$users = $repository->getAll();
And that is all!
Note: For now only create, get, and getAll actions are supported!
Custom Repository
You can also create a custom repository.
All you need to do is create class which extends KrzysztofMoskalik\ApiClient\AbstractRepository and override supports method:
public static function supports(): string
{
return User::class;
}
Now you can create custom methods and call built-in ones from them.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-21