-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kim Pepper <[email protected]>
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
- [Upgrading OpenSearch PHP Client](#upgrading-opensearch-php-client) | ||
- [Upgrading to >= 2.0.0](#upgrading-to--200) | ||
- [HTTP Client Auto-Discovery](#http-client-auto-discovery) | ||
- [Configuring Guzzle HTTP Client in 2.x](#configuring-guzzle-http-client-in-2x) | ||
- [Configuring Symfony HTTP Client in 2.x](#configuring-symfony-http-client-in-2x) | ||
|
||
# Upgrading OpenSearch PHP Client | ||
|
||
## Upgrading to >= 2.0.0 | ||
|
||
openseach-php removes the hard-coded dependency on the [Guzzle HTTP client](https://docs.guzzlephp.org/en/stable/#) and switches to the following PSR interfaces: | ||
|
||
- [PSR-7 HTTP message interfaces](https://www.php-fig.org/psr/psr-17/) | ||
- [PSR-17 HTTP Factories](https://www.php-fig.org/psr/psr-17/) | ||
- [PSR-18 HTTP Client](https://www.php-fig.org/psr/psr-18/) | ||
|
||
You can continue to use Guzzle, but will need to configure it as a PSR-18 HTTP Client. | ||
|
||
### HTTP Client Auto-Discovery | ||
|
||
opensearch-php 2.x will try and discover and install a PSR HTTP Client using [PHP-HTTP Discovery](https://docs.php-http.org/en/latest/discovery.html) | ||
if one is not explicitly provided. | ||
|
||
```php | ||
$transport = (new \OpenSearch\TransportFactory())->create(); | ||
$endpointFactory = new \OpenSearch\EndpointFactory(); | ||
$client = new Client($transport, $endpointFactory, []); | ||
|
||
// Send a request to the 'info' endpoint. | ||
$info = $client->info(); | ||
``` | ||
|
||
### Configuring Guzzle HTTP Client in 2.x | ||
|
||
To configure Guzzle as a PSR HTTP Client with the similar configuration to opensearch 1.x you can use the following example: | ||
|
||
```php | ||
$guzzleClient = new \GuzzleHttp\Client([ | ||
'base_uri' => 'https://localhost:9200', | ||
'auth' => ['admin', getenv('OPENSEARCH_PASSWORD')], | ||
'verify' => false, | ||
'retries' => 2, | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Content-Type' => 'application/json', | ||
'User-Agent' => sprintf('opensearch-php/%s (%s; PHP %s)', Client::VERSION, PHP_OS, PHP_VERSION), | ||
] | ||
]); | ||
$guzzleHttpFactory = new \GuzzleHttp\Psr7\HttpFactory(); | ||
$transport = (new OpenSearch\TransportFactory()) | ||
->setHttpClient($guzzleClient) | ||
->setPsrRequestFactory($guzzleHttpFactory) | ||
->setStreamFactory($guzzleHttpFactory) | ||
->setUriFactory($guzzleHttpFactory) | ||
->create(); | ||
|
||
$endpointFactory = new \OpenSearch\EndpointFactory(); | ||
$client = new Client($transport, $endpointFactory, []); | ||
``` | ||
|
||
### Configuring Symfony HTTP Client in 2.x | ||
|
||
You can configure [Symfony HTTP Client](https://symfony.com/doc/current/http_client.html) as a PSR HTTP Client using | ||
the following example: | ||
|
||
```php | ||
$symfonyPsr18Client = (new \Symfony\Component\HttpClient\Psr18Client())->withOptions([ | ||
'base_uri' => 'https://localhost:9200', | ||
'auth_basic' => ['admin', getenv('OPENSEARCH_PASSWORD')], | ||
'verify_peer' => false, | ||
'max_retries' => 2, | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Content-Type' => 'application/json', | ||
], | ||
]); | ||
|
||
$transport = (new OpenSearch\TransportFactory()) | ||
->setHttpClient($symfonyPsr18Client) | ||
->setPsrRequestFactory($symfonyPsr18Client) | ||
->setStreamFactory($symfonyPsr18Client) | ||
->setUriFactory($symfonyPsr18Client) | ||
->create(); | ||
|
||
$client = new Client($transport, $endpointFactory, []); | ||
|
||
// Send a request to the 'info' endpoint. | ||
$info = $client->info(); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters