bokbasen/php-api-client
最新稳定版本:v3.0.3
Composer 安装命令:
composer require bokbasen/php-api-client
包简介
Generic PHP API client for Bokbasen's API
README 文档
README
Click here if you're looking for documentation to version 1.*
Generic API client for use against all Bokbasen APIs where no spesific SDK is implemented that require authetication.
The HTTP client is simple in use and you must implement API spesific functionality yourself. But it provides a standard interface to do request against Bokbasen APIs and allow you to use the Login SDK handling any complexity related to authentication.
First create a Login object see php-sdk-auth for details
Installation
We are using HttpClientDiscovery so you'll need to require a PSR-7 compatible implementation, e.g.;
$ composer require php-http/guzzle6-adapter
Then add our package:
$ composer require bokbasen/php-api-client
Usage
use Bokbasen\Auth\Login; use Symfony\Component\Cache\Adapter\FilesystemAdapter; try { /* This example is using a file cache for the TGT, you can replace this with any PSR-6 compatible cache. Always using caching in production to avoid performance penalty of creating and deleting tokens. */ $cache = new FilesystemAdapter(); $login = new Login('username', 'password', Login::URL_PROD, $cache); } catch(\Throwable $e) { // error handling }
use Bokbasen\ApiClient\Client; use Bokbasen\ApiClient\HttpRequestOptions; use Bokbasen\ApiClient\Exceptions\BokbasenApiClientException; try { /* Pass the base URL of the API you are interacting with. You can also pass a logger and a custom http client. Any request made through the API returns an instance of \Psr\Http\Message\ResponseInterface. All of these API calls will include the necessary authentication headers. */ $client = new Client($login, 'https://loan.api.boknett.no'); // Execute get request, it is recommended to explicitly set accept parameter $headers = ['Accept' => HttpRequestOptions::CONTENT_TYPE_JSON]; $response = $client->get('/path', $headers); // Execute POST request with json data $response = $client->postJson('/path', $body, $headers); // Execute POST request $response = $client->post('/path', $body, $headers); // Execute PUT request $response = $client->put('/path', $body, $headers); // Execute PATCH request $response = $client->patch('/path', $body, $headers); } catch(BokbasenApiClientException $e){ //error handling }
Tests
$ ./vendor/bin/phpunit
统计信息
- 总下载量: 22.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-26