# 🌳 Upgrading from v2 Saloon version three comes with many improvements over version two, but most of the improvements were internal changes, so the upgrade to v3 from v2 shouldn't be too cumbersome. If you haven't already, it's recommended to read through ["What's new in v3"](whats-new-in-v3.md) to get an idea of what has changed before making the upgrade. ### Upgrade Saloon's Packages First of all, you should bump Saloon to the next major version in your `composer.json` file. You should also update any of the following plugins if you have them installed. * `saloonphp/saloon` to `^3.0` * `saloonphp/laravel-plugin` to `^3.0` * `saloonphp/cache-plugin` to `^3.0` * `saloonphp/laravel-http-sender` to `^2.0` * `saloonphp/rate-limit-plugin` to `^2.0` * `saloonphp/pagination-plugin` to `^2.0` After that, make sure to run the following command to update your `composer.lock` file and your `vendor` directory. ```bash composer update "saloonphp/*" ``` {% hint style="info" %} The above command will just update the `saloonphp` libraries. If you have other libraries using Saloon you should make sure that they are updated as well. {% endhint %} ### High Impact Changes High-impact changes will most likely be things that everyone needs to update. #### Minimum TLS 1.2 version enforced From version three, Saloon uses Guzzle `^7.6` which introduced a new option to configure a minimum TLS version. With Saloon v3, Saloon has set this default to **TLS 1.2.** If any of your API integrations require a lower level of TLS security, you can change the Saloon config while your application is loading. ```php FindReplaceuse Saloon\Contracts\Connectoruse Saloon\Http\Connectoruse Saloon\Contracts\Requestuse Saloon\Http\Requestuse Saloon\Contracts\PendingRequestuse Saloon\Http\PendingRequestuse Saloon\Contracts\Responseuse Saloon\Http\Response {% hint style="info" %} There have been many other interfaces removed in v3 however it's unlikely that your application would have used them. They are listed below. {% endhint %} #### HasBody Trait Renamed to HasStringBody During some of the code review to improve readability, the `HasBody` body trait has been renamed to `HasStringBody` to be more explicit. If any of your requests send a **plain string body**, you should find and replace this trait.
FindReplace
use Saloon\Traits\Body\HasBodyuse Saloon\Traits\Body\HasStringBody
use HasBodyuse HasStringBody
### Medium Impact Changes Medium-impact changes are changes that come up for some people but not others. #### SendAndRetry method argument name changes The second argument of the `$connector->sendAndRetry()` method has been renamed from `maxAttempts` to `tries`. If you are using named arguments then you will need to replace this name.
$connector->sendAndRetry(
    request: $request,
    tries: 5,
);
#### SendAndRetry handler now expects a Request class and not PendingRequest If you previously used the `handleRetry` argument when using `$connector->sendAndRetry()` - Saloon will now send an instance of `Request` instead of `PendingRequest` through the closure.
$connector->sendAndRetry(
    request: $request,
    tries: 5,
    interval: 0,
    handleRetry: static function (Throwable $exception, Request $request) {
        // $request->headers()->add();
    },
);
#### Config Method Changes With version three, some of the methods in the `Saloon\Config` class have been renamed. These changes have been listed below and you should make sure to rename them if you have used them in your application. | Find | Replace | | ----------------------------- | --------------------------------- | | `Config::middleware()` | `Config::globalMiddleware()` | | `Config::resetMiddleware()` | `Config::clearGlobalMiddleware()` | | `Config::resolveSenderWith()` | `Config::setSenderResolver()` | | `Config::setDefaultSender()` | `Config::$defaultSender =` | ### Low Impact Changes Low-impact changes are changes that are unlikely to come up unless you have overwritten some of Saloon's functionality or used its interfaces. It's still worth looking through to make sure you haven't missed anything. #### Methods Renamed On MockResponse On the `MockResponse` class Saloon had a few methods which have now been renamed to be more consistent with the rest of Saloon. These changes are: * `getBody()` has changed to `body()` * `getHeaders()` has changed to `headers()` * `getStatus()` has changed to `status()` #### Middleware Arguments Changed Saloon v3 introduced the ability to reorder middleware. With this, the old `prepend` argument on middleware methods has been replaced with a `pipeOrder` argument. Additionally, the second argument for the middleware is now `name` . #### Methods Removed From PendingRequest Class The following methods have now been removed from the `PendingRequest` class. You can use the suggested replacement if you are using them in your application.
OldSuggested Replacement
$pendingRequest->send()$pendingRequest->getConnector()->send()
$pendingRequest->sendAsync()$pendingRequest->getConnector()->sendAsync()
$pendingRequest->getSender()$pendingRequest->getConnector()->sender()
#### Promise Execution Changes Previously, Saloon's `PendingRequest` and middleware would be invoked before an asynchronous request was sent (using `$connector->sendAsync()`) - now Saloon has fixed this issue and the `PendingRequest` and middleware will only be invoked while the `Promise` is being resolved - at the same time as sending the request. If your application depended on the old way the middleware was invoked you should make sure your application isn't affected by this change. #### SimulatedResponsePayload Class Renamed Previously, the `MockResponse` would extend a class called `SimulatedResponsePayload`. This class has now been renamed to `FakeResponse`. Additionally, methods on the `PendingRequest` like `$pendingRequest->setSimulatedResponsePayload()` has been renamed to `$pendingRequest->setFakeResponse()`. If you were extending the old class or using the methods to set the fake response in middleware, you should rename these methods. #### Sender Contract Updated The `Sender` interface has been completely rewritten in Saloon v3. Instead of just the `sendRequest` method. You now have to define three methods. If you have made a custom sender in Saloon, you should make sure this is updated. ```php Show Removed Interfaces * src/Contracts/Arrayable.php * src/Contracts/Authenticatable.php * src/Contracts/CanThrowRequestExceptions.php * src/Contracts/Connector.php * src/Contracts/DebuggingDriver.php * src/Contracts/Dispatcher.php * src/Contracts/HasConfig.php * src/Contracts/HasDebugging.php * src/Contracts/HasDelay.php * src/Contracts/HasHeaders.php * src/Contracts/HasMiddlewarePipeline.php * src/Contracts/HasMockClient.php * src/Contracts/HasPagination.php * src/Contracts/HasQueryParams.php * src/Contracts/IntegerStore.php * src/Contracts/MiddlewarePipeline.php * src/Contracts/MockClient.php * src/Contracts/Paginator.php * src/Contracts/PendingRequest.php * src/Contracts/Pipeline.php * src/Contracts/Pool.php * src/Contracts/Request.php * src/Contracts/Response.php * src/Contracts/SimulatedResponsePayload.php #### The Base BodyRepository Class Is No Longer Stringable If you have made your own `BodyRepository` class from the base class and relied on the `__toString` method this has now been removed. Additionally, the interface has been updated and now requires a `toStream()` method. Inside here, you must define how to convert your body type into a Stream using the provided `StreamFactory`. #### Timeout Enum Removed The old `Timeout` enum has now been removed. If your application used to use this method, you should migrate to use `Config::$defaultConnectionTimeout` and `Config::$defaultRequestTimeout`. #### ToArray Method Removed From MultipartValue Previously, the `MultipartValue` object had a `toArray` method. Now that all body repositories are converted into Streams, this method is no longer required. #### SimulatedSender Removed The `SimulatedSender` class which would be used if you were mocking or had a cached response has now been removed. ### Did we miss anything? If we forgot to add something to this upgrade please let us know by [opening an issue](https://github.com/saloonphp/saloon/issues).