Skip to content

Commit 3a69796

Browse files
author
simialbi
authored
Merge pull request #13 from softedge/update-readme
Updated documentation
2 parents e7cd6dd + aed00ec commit 3a69796

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,21 @@ To use this extension, configure restclient component in your application config
4949
],
5050
```
5151

52-
| Parameter | Description |
53-
| ------------------ | ---------------------------------------------------------------------------------------------------------------- |
54-
| `baseUrl` | The location of the api. E.g. for http://api.site.com/v1/users the `baseUrl` would be http://api.site.com/v1/ |
55-
| `auth` | Either a Closure which returns a `string` or a `string`. The rest connection will be passed as parameter. |
56-
| `usePluralisation` | Whether to use plural version for lists (index action) or not (e.g. http://api.site.com/users instead of `user`) |
57-
| `useFilterKeyword` | Whether to use "filter" key word in url parameters when filtering (e.g. ?filter[name]=user instead of ?name=user |
58-
| `enableExceptions` | Whether the connection should throw an exception if response is not 200 or not |
59-
| `itemsProperty` | If your items are wrapped inside a property (e.g. `items`), set it's name here |
52+
| Parameter | Default | Description |
53+
| ------------------- | -----------| ------------------------------------------------------------------------------------------------------------- |
54+
| `baseUrl` | `''` | The location of the api. E.g. for http://api.site.com/v1/users the `baseUrl` would be http://api.site.com/v1/ (required) |
55+
| `auth` | | Either a Closure which returns a `string` or a `string`. The rest connection will be passed as parameter. |
56+
| `usePluralisation` | `true` | Whether to use plural version for lists (index action) or not (e.g. http://api.site.com/users instead of `user`) |
57+
| `useFilterKeyword` | `true` | Whether to use "filter" key word in url parameters when filtering (e.g. ?filter[name]=user instead of ?name=user |
58+
| `enableExceptions` | `false` | Whether the connection should throw an exception if response is not 200 or not |
59+
| `itemsProperty` | | If your items are wrapped inside a property (e.g. `items`), set it's name here |
60+
| `requestConfig` | `[]` | Client request configuration |
61+
| `responseConfig` | `[]` | Client response configuration |
62+
| `updateMethod` | `'put'` | The method to use for update operations. |
63+
| `isTestMode` | `false` | Whether we are in test mode or not (prevent execution) |
64+
| `enableQueryCache` | `false` | Whether to enable query caching |
65+
| `queryCacheDuration`| `3600` | The default number of seconds that query results can remain valid in cache |
66+
| `queryCache` | `'cache'` | The cache object or the ID of the cache application component |
6067

6168
## Usage
6269
Define your Model

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"minimum-stability": "beta",
2828
"require": {
29-
"php": ">=5.6",
29+
"php": ">=7.0",
3030
"yiisoft/yii2": "^2.0.14",
3131
"yiisoft/yii2-httpclient": "^2.0.0"
3232
},

src/Connection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use yii\httpclient\Client;
1717
use yii\httpclient\Response;
1818
use yii\web\HeaderCollection;
19+
use simialbi\yii2\rest\Exception as RestException;
1920

2021
/**
2122
* Class Connection
@@ -25,9 +26,7 @@
2526
* 'components' => [
2627
* 'restclient' => [
2728
* 'class' => 'simialbi\yii2\rest\Connection',
28-
* 'config' => [
29-
* 'base_uri' => 'https://api.site.com/',
30-
* ],
29+
* 'baseUrl' => 'https://api.site.com/',
3130
* ],
3231
* ],
3332
* ```
@@ -496,13 +495,13 @@ protected function request($method, $url, $data = [])
496495
try {
497496
$this->_response = $this->isTestMode ? [] : $request->send();
498497
} catch (\yii\httpclient\Exception $e) {
499-
throw new Exception('Request failed', [], 1, $e);
498+
throw new RestException('Request failed', [], 1, $e);
500499
}
501500
Yii::endProfile($profile, __METHOD__);
502501

503502
if (!$this->isTestMode && !$this->_response->isOk) {
504503
if ($this->enableExceptions) {
505-
throw new Exception($this->_response->content, $this->_response->headers->toArray());
504+
throw new RestException($this->_response->content, $this->_response->headers->toArray());
506505
}
507506
return false;
508507
}

0 commit comments

Comments
 (0)