@@ -152,7 +152,7 @@ check the [`addResponseContentsHandler`](#addresponsecontentshandler) method in
152152
153153#### ` buildPath `
154154
155- The purpose of this method is to have an easy way to build a properly formatted path URL depending on the inputs or parameters you might have.
155+ The purpose of this method is to have an easy way to build a properly formatted path depending on the inputs or parameters you might have.
156156
157157``` php
158158$this->buildPath(string $path, array $parameters): string;
@@ -211,9 +211,8 @@ class YourApi extends Api
211211{
212212 public function __construct(string $language = 'en')
213213 {
214- parent::__construct();
214+ // ...
215215
216- $this->setBaseUrl('https://api.example.com/v1');
217216 $this->addQueryDefault('lang', $language);
218217 }
219218
@@ -271,9 +270,8 @@ class YourApi extends Api
271270{
272271 public function __construct(string $language = 'en')
273272 {
274- parent::__construct();
273+ // ...
275274
276- $this->setBaseUrl('https://api.example.com/v1');
277275 $this->addHeaderDefault('X-LANGUAGE', $language);
278276 }
279277
@@ -343,10 +341,13 @@ class YourApi extends Api
343341{
344342 public function __construct(string $applicationKey)
345343 {
346- parent::__construct();
344+ // ...
347345
348- $this->setBaseUrl('https://api.example.com/v1');
349- $this->setAuthentication(new QueryParam(['api_token' => $applicationKey]));
346+ $this->setAuthentication(
347+ new QueryParam([
348+ 'api_token' => $applicationKey
349+ ])
350+ );
350351 }
351352
352353 public function getPosts(): string
@@ -389,7 +390,9 @@ class YourApi extends Api
389390
390391 // a PostRequestEvent is passed as an argument
391392 $this->addPostRequestHandler(function(PostRequestEvent $event) {
392- // $event->getRequest() is also available
393+ // request data is also available
394+ // $request = $event->getRequest();
395+
393396 $response = $event->getResponse();
394397 $statusCode = $response->getStatusCode();
395398
@@ -411,7 +414,7 @@ class YourApi extends Api
411414
412415#### ` addResponseContentsHandler `
413416
414- On the other hand, the ` addResponseContentsHandler ` method is used to manipulate the response that was received from the API.
417+ The ` addResponseContentsHandler ` method is used to manipulate the response that was received from the API.
415418This event listener will be applied to every API request.
416419
417420``` php
@@ -562,11 +565,13 @@ $this->getClientBuilder()->addPlugin(Plugin $plugin, int $priority): self;
562565It is important to know that this library already uses various plugins with different priorities.
563566The following list has all the implemented plugins with the respective priority in descending order (remember that order matters):
564567
565- - [ ` ContentTypePlugin ` ] ( https://docs.php-http.org/en/latest/plugins/content-type.html ) : ` 40 `
566- - [ ` ContentLengthPlugin ` ] ( https://docs.php-http.org/en/latest/plugins/content-length.html ) : ` 32 `
567- - [ ` AuthenticationPlugin ` ] ( https://docs.php-http.org/en/latest/plugins/authentication.html ) : ` 24 ` (only if authentication is enabled)
568- - [ ` CachePlugin ` ] ( https://docs.php-http.org/en/latest/plugins/cache.html ) : ` 16 ` (only if cache is enabled)
569- - [ ` LoggerPlugin ` ] ( https://docs.php-http.org/en/latest/plugins/logger.html ) : ` 8 ` (only if logger is enabled)
568+ | Plugin | Priority | Note |
569+ | --------------------------------------------------------------------------------------------| ----------| -----------------------------------|
570+ | [ ` ContentTypePlugin ` ] ( https://docs.php-http.org/en/latest/plugins/content-type.html ) | 40 | |
571+ | [ ` ContentLengthPlugin ` ] ( https://docs.php-http.org/en/latest/plugins/content-length.html ) | 32 | |
572+ | [ ` AuthenticationPlugin ` ] ( https://docs.php-http.org/en/latest/plugins/authentication.html ) | 24 | only if authentication is enabled |
573+ | [ ` CachePlugin ` ] ( https://docs.php-http.org/en/latest/plugins/cache.html ) | 16 | only if cache is enabled |
574+ | [ ` LoggerPlugin ` ] ( https://docs.php-http.org/en/latest/plugins/logger.html ) | 8 | only if logger is enabled |
570575
571576For example, if you wanted the client to automatically attempt to re-send a request that failed
572577(due to unreliable connections and servers, for example)
@@ -584,7 +589,7 @@ class YourApi extends Api
584589
585590 // if a request fails, it will retry at least 3 times
586591 // priority is 12 to execute the plugin between the cache and logger plugins
587- // (check the above plugin order list for more information)
592+ // (check the above plugin order list for more information)
588593 $this->getClientBuilder()->addPlugin(
589594 plugin: new RetryPlugin(['retries' => 3])
590595 priority: 12
@@ -627,7 +632,7 @@ new CacheBuilder(
627632 $methods = ['GET', 'HEAD'],
628633 // An array of cache directives to be compared with the headers of the HTTP response,
629634 // in order to determine cacheability
630- $responseCacheDirectives = ['no-cache', ' max-age']
635+ $responseCacheDirectives = ['max-age']
631636);
632637```
633638
@@ -733,7 +738,7 @@ use ProgrammatorDev\Api\Builder\LoggerBuilder;
733738$this->getLoggerBuilder(): LoggerBuilder;
734739```
735740
736- As an example, if you wanted to save log into a file:
741+ As an example, if you wanted to save logs into a file:
737742
738743``` php
739744use ProgrammatorDev\Api\Api;
@@ -750,7 +755,7 @@ class YourApi extends Api
750755 $logger = new Logger('api');
751756 $logger->pushHandler(new StreamHandler('/logs/api.log'));
752757
753- $this->setClientBuilder (
758+ $this->setLoggerBuilder (
754759 new LoggerBuilder(
755760 logger: $logger
756761 )
@@ -767,7 +772,7 @@ $api = new YourApi();
767772$logger = new Logger('api');
768773$logger->pushHandler(new StreamHandler('/logs/api.log'));
769774
770- $api->setClientBuilder (
775+ $api->setLoggerBuilder (
771776 new LoggerBuilder(
772777 logger: $logger
773778 )
0 commit comments