Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Latest
------

### Changes
* [#84](https://github.com/cleverage/rest-process-bundle/issues/84) Documentation: working `#[AsRestClient]` example, exceptions of the bundle in the reference pages.

v3.3.1
------

Expand Down
10 changes: 10 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ services:
- { name: cleverage.rest.client, code: apicarto_ign }
```

With autoconfiguration, the `#[AsRestClient(code: 'apicarto_ign')]` attribute on a class extending `Client` adds the
same tag (see [REST client](reference/client.md)).

The [RequestTask](reference/tasks/request_task.md) then references this client by its code:

```yaml
Expand All @@ -72,3 +75,10 @@ No option can be configured under `cleverage_rest_process`: a key there is ignor
- Tasks
- [RequestTask](reference/tasks/request_task.md)
- [CleverAge/ProcessBundle documentation](https://github.com/cleverage/process-bundle/blob/main/docs/index.md)

## Exceptions

The exceptions named without namespace in the reference pages (e.g. `UnexpectedValueException`) are the ones of the
bundle, `CleverAge\RestProcessBundle\Exception\*`: they extend the SPL exceptions of the same name and implement
`CleverAge\ProcessBundle\Exception\ProcessExceptionInterface`, so that all the errors of the process bundles can be
caught at once.
9 changes: 8 additions & 1 deletion docs/reference/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The request is then built this way:
- **URL**: `<base URI>/<url>`, the leading `/` of `url` being removed. Then each `{key}` of `url_parameters` is
replaced by its value, converted to a string and encoded with
[`rawurlencode()`](https://www.php.net/manual/en/function.rawurlencode.php) (a non-scalar value throws an
`\UnexpectedValueException`).
`UnexpectedValueException`).
- **Method**: must be one of `HEAD`, `GET`, `POST`, `PUT`, `DELETE`, `OPTIONS`, `TRACE`, `PATCH` (case-sensitive),
otherwise a `CleverAge\RestProcessBundle\Exception\RestRequestException` (`<method> is not an HTTP method`) is thrown.
- **Headers**: `headers`, plus `Content-Type: <sends>` and `Accept: <expects>` when these options are not empty
Expand Down Expand Up @@ -84,10 +84,17 @@ The `#[AsRestClient]` attribute adds the same tag to an autoconfigured service:
```php
use CleverAge\RestProcessBundle\Attribute\AsRestClient;
use CleverAge\RestProcessBundle\Client\Client;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

#[AsRestClient(code: 'my_api')]
class MyApiClient extends Client
{
public function __construct(HttpClientInterface $httpClient, LoggerInterface $logger)
{
// The code must be the one of the attribute
parent::__construct($httpClient, $logger, 'my_api', 'https://api.example.com');
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/tasks/request_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Accepted inputs
`array` or empty value (`null`, `[]`...): request options overriding the task options (shallow merge, the input wins).
Allowed keys are `url`, `method`, `headers`, `url_parameters`, `sends`, `expects` and `data`: any other key is passed to
the client, which rejects it (the default client throws an `UndefinedOptionsException`). Any other non-empty input
(e.g. a `string`) throws an `\UnexpectedValueException`.
(e.g. a `string`) throws an `UnexpectedValueException`.

Possible outputs
----------------
Expand Down
Loading