saloon icon indicating copy to clipboard operation
saloon copied to clipboard

Version 2 is coming šŸ¤ 

Open Sammyjo20 opened this issue 2 years ago ā€¢ 14 comments

Quick Update: Work has been quite busy at the moment so I haven't had a chance to dive into V2 for a while, but V2 will definitely be here before the end of 2022! It's not too far away šŸŽ‰

--

Hey everyone, thanks so much for all the support that you have given for Saloon. I can't believe it's almost at 500 stars on GitHub and receiving over 150 installs a day. I just wanted to take a moment to thank you all! šŸ˜€šŸ™Œ

That being said, there are some good things coming to Saloon. I'm working on version 2, which will help create a road for the future of Saloon, as well as improving developer experience and making your life easier.

Here is a summary of the changes that are going to happen.

New Flow

Currently, Saloon will run your request through the "Request Manager" which merges all of the headers, config, and everything else from the connector and request into one. With Version 2, I am introducing the "PendingSaloonRequest". Inside of here, this is where all of the logic like merging properties together and running your plugins will happen. This is so the building of a request is entirely separate from the sending of requests. After that, it will be sent to the "Guzzle Sender", and the class will receive the full PendingSaloonRequest with all the final configuration and headers before sending.

I am changing to this new flow because eventually, I want Saloon to be HTTP client agnostic and allow you to use any client you like, so you don't have to use Guzzle if you don't want - and if Guzzle decides to be abandoned, Saloon won't be left in the dark.

Here's the new flow in detail.

image

The only exception to the flow in the image above is that it will not create a PSR-7 request just yet, I am still working that one out.

Other Changes

  • Brand new middleware pipeline so you don't have to rely on Guzzle's handler pipeline
  • Requests donā€™t go straight to the request manager anymore, they can be built within a PendingSaloonRequest.
  • DTOs are going to be a first-party feature
  • Better way to send data, by implementing interfaces that are processed by the PendingSaloonRequest.
  • All properties of a request like headers, config, data, handlers etc. Will all be standardised and now in separate buckets like $requestā†’headers()ā†’push().
  • Interfaces to be used a lot more
  • PHP 8.1 minimum
  • Real asynchronous request
  • Request pooling support

Middleware Pipeline

To help move the dependency on Guzzle, Saloon has also implanted its own middleware pipeline for requests and responses. This will replace the old Guzzle Handler support and response interceptors. You will be able to define request pipes and response pipes to modify the request/response before it is sent or given back to the user.

$request = new GetForgeServersRequest;

$request->middleware()
    ->addRequestPipe(function (PendingSaloonRequest $request) {
       //
    })
    ->addRequestPipe(new MyInvokableClass)
     ->addResponsePipe(function (SaloonResponse $response) {
       //
    })

Saloon's middleware pipeline will also be supported for asynchronous requests, so even if you have a pool of requests being sent simultaneously, they can each have their own middleware pipeline, which is something that Guzzle does not support with their existing handler stack logic, since you can only have one handler stack per client.

Middleware pipes can be added anywhere. Inside the request/connector, added by plugins, or even applied right before a request is sent. It will really allow you to tap into Saloon.

External API

Saloonā€™s external API will still remain the same, like the following:

<?php

$request = new GetForgeServersRequest;
$response = $request->send($mockClient);

$connnector = new ForgeConnector;
$request = $connector->request(new GetForgeServersRequest)->send();
$response = $request->send();

// Or

$connector->send($request);

There will be some additions to the external API, like interacting with request properties

<?php

// Before

$request = new GetForgeServersRequest;
$request->addHeader('X-User-Name', 'Sammy');
$request->addConfig('debug', true);
$config = $request->getConfig(); // Array

// Now

$request->headers()->push('X-User-Name', 'Sammy');
$request->config()->push('debug', true);

$config = $request->config()->all();

// Same with config, handlers, response interceptors, etc.

There will also be some new features, like the ability to set a mock client on the connector or a request, so it doesnā€™t have to be passed into the send of every request.


<?php

$request = new GetForgeServersRequest;
$request->withMockClient($mockClient);
$request->send(); // Won't need to set it here!

// Even more useful

$connector = new ForgeConnector;
$connector->withMockClient($mockClient);

// All requests using the connector will use the same mock client!

$connector->request($requestA)->send();
$connector->request($requestB)->send();

Sammyjo20 avatar Jun 11 '22 22:06 Sammyjo20

Hey, @Sammyjo20. First off - obviously no stress, just wanted to check in. šŸ™‚

How far would you say you've come on this? Do you happen to have some documentation and/or notes started, that one could possibly look at?

I've just started looking into both Saloon v2 and Spatie's Laravel Data v2. I'm not really in a hurry right now (waiting for releases before upgrading), but would like to start experimenting and possibly start making the way for an upgrade, if possible, so I have some new features already using these packages.

As always, thanks for this excellent package, and the superb support. ā¤ļø

juse-less avatar Jun 15 '22 18:06 juse-less

Hey @juse-less,

Thanks for the message - at the moment v2 is in a bit of a funny state, Iā€™ve got a basic request working from start to finish, using the brand new PendingSaloonRequest. Thatā€™s pretty much done. The GuzzleSender is about 90% complete and Iā€™m confident that async requests are working properly. However a lot of the tests (pretty much all) are borked at the moment, so I wouldnā€™t trust all of it.

Overall Iā€™d say Iā€™m about 60% of the way through. The core is in there you can add everything like headers, config, plugins and the brand new middleware pipeline is working very very well.

Iā€™m currently working on the mocking. Since I no longer use Guzzleā€™s handler stack, I need to build in ā€œearly responsesā€ into the middleware/sending pipeline. Iā€™ve got a prototype working.

After Iā€™ve sorted the mocking, it will just be plumbing in all the extra bits like laravel support and OAuth2, but thatā€™s all pretty easy since a lot of it is backwards compatible (except the new headers/config syntax)

I know you are probably anxious about using the async requests, and I can say with confidence that request pooling will work, and youā€™ll be able to maintain custom config and middleware pipelines for every request. Itā€™s really going to be the dream. Iā€™m also thinking of building pools like this:

$connector = new MyConnector;

$connector->pool([ new RequestOne, new RequestTwo ])->then()->catch()

and of course youā€™ll be able to use a generator or maybe an invokable class for the requests.

The way it works is once a request is sent once, we store the request sender on the connector, keeping the current guzzle client open and ready for more requests.

Hope this helps!

P.S I am about to go on holiday for 11 days and I wonā€™t have my laptop, but I canā€™t wait to get back to coding v2 when I am back!

Sammyjo20 avatar Jun 15 '22 23:06 Sammyjo20

As soon as I have a stable-ish API Iā€™ll try to public v2 alphas / betas for you

Sammyjo20 avatar Jun 15 '22 23:06 Sammyjo20

Thanks! That sounds amazing.

The pooling should solve a weird issue we're having with libcurl starting to fail to resolve hosts after ~10 minutes, depending on how quickly we send requests. The only solution is to restart our Laravel queue workers, or wait for like.. 15-30 minutes before it self-heals (after hundreds of failed Jobs we need to requeue). I've tried all sorts of settings and configs in Guzzle (even for libcurl directly), to no avail. I haven't tested PHP's cURL directly, though, but definitely a weird issue.

Nonetheless. Can't wait for it. šŸ˜Š

Have a great holiday!

juse-less avatar Jun 15 '22 23:06 juse-less

Very strange! Hopefully the pooling will fix the issue. Did pooling fix the problem when you used Guzzle alone?

Itā€™s my pleasure, thank you!

Sammyjo20 avatar Jun 16 '22 08:06 Sammyjo20

I never tried pooling in Guzzle, actually. I just used Laravel's HTTP Client at the time, and quickly tried sending requests with Guzzle directly. This was also at the time while I was also mid-converting to Saloon to actually use async requests (we used sync with Laravel). So I did try both sync and async with Guzzle. As you might've guessed, it became even more apparent when we moved to using async requests, since we send 3-5 requests concurrently. Our solution for now is to simply restart all Queue workers after 5 minutes, to ensure we don't have a long-running job making it surpass that 10 minute marker.

The problem seems to be that keep-alive requests are being sent (or at least connection handles not being closed correctly), and the handles remain open, causing the whole process (Laravel's Queue worker) to run out of file handles. I tried disabling keep-alive, enforce HTTP 1.0, etc. But, for some reason, none of seems to do it. I guess I could just try increasing file handles and see if it can cope with more requests, but.. doesn't feel like an adequate solution. Since we're doing so many requests to begin with, the correct option would really be to use pooling. So hopefully it's solved once we move to pooling to keep the connection open, instead of initiating thousands of requests.

I did quickly try both HTTP/2 and HTTP/3, actually, but couldn't get it to work, and didn't have the headroom to test if all different external systems supports either to begin with.

juse-less avatar Jun 16 '22 11:06 juse-less

Hey @juse-less - other than the proper support for Async requests, is there anything else in v2 that you need? I may branch out and build request pooling support into v1, with the assumption that Guzzle middleware won't work on the request level.

I'm saying this just because I want to take my time a bit more with v2 and there's going to be quite a lot of work with rewriting the documentation, upgrade guides etc, so I'm wondering if I can help out with the mini feature in v1.

Otherwise, I could suggest that you go back to using your Guzzle approach for the parts of the app that were causing problems because of Saloon's async requests?

Sammyjo20 avatar Jun 29 '22 15:06 Sammyjo20

@Sammyjo20 I think it's ok for now. I appreciate you asked, but I think it's better if you focus on v2. šŸ™‡ā€ā™€ļø

I apologise for the confusion - what I meant is that I tried with Guzzle as well, but to no avail. The problem is seemingly that it's opening a new 'file' for each request, and, despite setting libcurl constants (or Guzzle settings) directly in Guzzle, it still didn't fix the underlying issue. So, ultimately, it would appear that the only option is to support pooling. But I never tried pooling itself, just tried getting Guzzle/libcurl to close the handles in-between async requests.

I think the temporary solution I have in place also helps a bit preventing us from being banned from external systems and we push a lot of requests back and forth. Other than.. not sending that many requests (and frequently), obviously. šŸ˜›

So, that said, I really appreciate you asked and trying to help me with my situation. But I definitely think it's worth just focusing on v2. šŸ™‚

juse-less avatar Jun 29 '22 16:06 juse-less

Thanks for the clarification @juse-less ! šŸ™Œ

I have some other work commitments I also need to spend my time on so v2 might be a bit longer than my initial 4-6 week estimation, but I'll keep updating this when I have more progress to mention. I'm really happy with how v1 works and I think v1 will be fine for most people for the next few months.

If you have any suggestions for v2 please don't hesitate to say!

Sammyjo20 avatar Jun 29 '22 16:06 Sammyjo20

I have a few ideas, that I can write down next week, or so, as I have some work commitments myself (started a tight 2 week sprint today even). v1 is definitely more than enough. Since I can set Guzzle settings through Saloon already, I could possibly solve my issue in v1 as well, if I can just figure out the Guzzle/libcurl settings to apply.

One thing that directly comes to mind, however, when I quickly tried the parts of v2 last week (but behaves the same in v1), is the usage of interfaces. I actually register my various connectors, requests, and responses inside the Laravel container. This is currently not possible, the way that Saloon instantiates the defined class strings from the connector/request/response class string properties. So, I think there are 2 possibilities.

  1. Have the Laravel Saloon package overwrite certain parts to resolve things from the Laravel service container, or
  2. Easily let us override the sort of.. resolving mechanics, so we can easily call the container with our interface, to resolve the implementation. I think this one would be more versatile, as Saloon isn't Laravel-specific. So, letting developers resolve it, they could use other service containers, or other complex logic to resolve them.

It's probably only connectors and responses I'm thinking of, since requests are created directly, but mentioned all 3, just in case.


If you'd like to try something out later on (performance, resource usage, or otherwise), I can definitely try it in our internal tool I'm building.

juse-less avatar Jun 29 '22 16:06 juse-less

Version 1 is awesome - version 2 will be even better I can see šŸ˜‰ Thanks @Sammyjo20.

The idea about interchangeable HTTP client using PSR-7, PSR-17 and PSR-18 sounds awesome! A good add-on might be adding a compatible driver for the Laravel HTTP Client. I know that under the hood this is using Guzzle, but so many things in the Laravel community is build around this, so you get easy integration with almost anything using that - examples could be:

bilfeldt avatar Aug 06 '22 12:08 bilfeldt

Thanks for the message @bilfeldt that means a lot!

I agree it would be amazing to use the existing tools that wrap around Laravel's HTTP client. I will likely release V2 with just Guzzle support initially since that will make it on-par with version one, but the way it's designed, it would be super easy to write a custom adapter for the HTTP client.

Thanks for the feedback and for enlightening me on the idea!

Sammyjo20 avatar Aug 06 '22 22:08 Sammyjo20

Hello @Sammyjo20 - and thank you for your package! I've started using it and i'm really happy with it.

I was wondering if you need any help on getting v2 out the door ?

niladam avatar Sep 14 '22 10:09 niladam

Hey @niladam

Thank you for the offer but I'm all good, I am getting there but had to stop because work is so busy at the moment and I think I'd fall apart if I worked extra in the evening šŸ˜‚

I think V2 is definitely going to be here before the end of the year so hang tight!

I will let you know if I need someone to peer review/help me because that would be very helpful.

Sammyjo20 avatar Sep 14 '22 12:09 Sammyjo20

Just a little update, I've been starting back up my work for v2! šŸ™Œ

I've gone back through my todo list and created a fresh one with all the tasks I want to complete. I will keep the thread updated as progress comes along. My goal is to have it ready before the end of the year, but it may be January when it is released. January would mark Saloon's 1 year anniversary so that would be relevant :D

Sammyjo20 avatar Oct 25 '22 16:10 Sammyjo20

Hello again everyone! I wanted to share with you an update on the progress of v2 as I feel itā€™s approaching the time where I am not introducing any more breaking changes, but I wanted to ask your opinion on the developer experience and how you will feel with a few breaking changes.

Just wanted to note that V2 is NOT ready to be used, even in an alpha state. I need to rewrite a lot of tests and battle-test it. The following is not an upgrade guide either, I am just looking for some feedback before I continue.

Goal

The Goal with v2 is to simplify Saloonā€™s codebase, make it more future proof and reduce its dependancy on Guzzle allowing it to be used with any HTTP client in the future. V2 also uses a lot more of PSR-7 and full PSR-7 support will likely be released in v3. The gap between v2 and v3 will be much smaller since less breaking changes will be required.

(New, Breaking) PendingSaloonRequest

Previously when you sent a request, Saloon would pass your request instance through the ā€œrequest managerā€. This class would be very closely tied to the HTTP Client (Guzzle) and the entire class was responsible for merging together query parameters, configuration, data and triggering things like authenticators.

Saloon now has a PendingSaloonRequest. This class when created will merge everything together into the one PendingSaloonRequest instance. This prevents the original SaloonRequest class from being polluted with mutations, and also allows Saloon to have a separate class that is built before passing it onto the HTTP Client.

Inside the PendingSaloonRequestā€™s constructor, it runs various methods to ā€œbuild upā€ the pending request.

// PendingSaloonRequest.php / Constructor

$this
  ->registerDefaultMiddleware()
  ->mergeRequestProperties()
  ->mergeData()
  ->bootConnectorAndRequest()
  ->bootPlugins()
  ->authenticateRequest();

This also allows Saloon in the future to convert this class into a PSR-7 request with minimal effort, since itā€™s already separate.

[Click here to see an example of PendingSaloonRequest](https://github.com/Sammyjo20/Saloon/blob/v2/src/Http/PendingSaloonRequest.php)

(New) Senders

Once a PendingSaloonRequest is created, it will check if a MockResponse has been set. If one hasnā€™t been set it will pass the PendingSaloonRequest into a ā€œsenderā€. This sender class is a wrapper around a HTTP Client. The default sender that will ship with Saloon v2 will be the GuzzleSender. Inside of this class, you are required to specify a ā€œsendRequestā€ method.

The sender instance is created once on the connector and then will be re-used for every request. This allows us to keep the HTTP Client open and allows Saloon to finally support true asynchronous requests. More on that later.

This new sender class will allow Saloon to easily support other HTTP clients in the future without breaking Saloonā€™s internal logic. This is super exciting because Saloon no longer needs to depend on Guzzle to work. You can customise the sender inside of your own application too if you choose to make your own sender logic.

Another benefit of the senders logic over v1 is that the request and the HTTP client logic is now separated which reduces code complexity.

[Click here to see an example of the GuzzleSender](https://github.com/Sammyjo20/Saloon/blob/v2/src/Http/Senders/GuzzleSender.php)

(Updated, Breaking) Headers, Query Parameters, Config & Data

Saloon v2 also improves the way headers, query parameters, config and data is interacted with. Previously, each bucket of information lived in its own trait. They were inconsistent and sometimes didnā€™t make too much sense. Iā€™ve now built a standardised ā€œContentBagā€ class inspired by Laravelā€™s MessageBag and ErrorBag classes. These are standardised repository classes that allow you to interact with them each in the same way.

Letā€™s look at some examples of managing headers.

Old Way

$request = new UserRequest;

$request->addHeader('X-Name', 'Sam');
$request->mergeHeaders([])
$request->setHeaders(['X-Foo' => 'Bar'])
$request->getHeaders(); // array
$request->getHeader('X-Name') // string

New Way

$request = new UserRequest;

$request->headers()->add('X-Name', 'Sam')
$request->headers()->merge([])
$request->headers()->set(['X-Foo' => 'Bar'])
$request->headers()->all()
$request->headers()->get('X-Name') 

The same is true for query, data and config. This is a breaking change, but it massively reduces the complexity of code and makes it easier to test.

Another benefit of using the method access is that default headers will show up! Previously, if you had set an array of default headers in your request and then tried to access the headers by using $request->getHeaders it wouldnā€™t have shown you the default. Now it will show you the default headers, but it wonā€™t show the default headers on the connector.

The same logic has been shared for query, data and config

$request = new UserRequest;

$request->query()->add()

$request->config()->add()

$request->data()->add()

(Breaking) Data Interfaces Replacing Traits

Previously when you wanted to tell Saloon that a request or connector will have data, you would have to use a plugin like this:

class CreateForgeSiteRequest extends SaloonRequest
{
    use HasJsonBody;

Saloon now has switched to interfaces for data.

class CreateForgeSiteRequest extends SaloonRequest implements SendsJsonBody
{

This is because previously the plugin would add a Guzzle-specific configuration option that adds a JSON, form or multipart body. Saloon will now handle this for you.

(New) Middleware Pipeline

To help move the dependency on Guzzle, Saloon has also implanted its own middleware pipeline for requests and responses. This will replace the old Guzzle Handler support and response interceptors. You will be able to define request middleware and response middleware to modify the request/response before it is sent or given back to the user.

It will support closures and accept a PendingSaloonRequest or an invokable class.

$request = new GetForgeServersRequest;

$request->middleware()
    ->onRequest(function (PendingSaloonRequest $request) {
       //
    })
    ->onRequest(new MyInvokableClass)
    ->onResponse(function (SaloonResponse $response) {
       //
    });

Saloon's middleware pipeline will also be supported for asynchronous requests, so even if you have a pool of requests being sent simultaneously, they can each have their own middleware pipeline, which is something that Guzzle does not support with their existing handler stack logic, since you can only have one handler stack per client.

Middleware pipes can be added anywhere. Inside the request/connector, added by plugins, or even applied right before a request is sent. It will really allow you to tap into Saloon.

It also will across any HTTP Client so in the future if Guzzle is not used, this middleware functionality is Saloon feature.

(Updated, New) Concurrent Requests & Pooling

Saloonā€™s old design meant that asynchronous requests just didnā€™t work. This was because every request would create a new Guzzle client, send the request and destruct the object. With Saloonā€™s new sender logic, Saloon v2 will keep the HTTP Client in memory on the connector. With some caveats.

The following example will not work because a new connector instance will be defined on every request. You must instantiate the connector and use the same connector or use the pool method.

// Will not work

$requestA = new CreateForgeSiteRequest;
$requestB = new CreateForgeSiteRequest;
$requestC = new CreateForgeSiteRequest;

$requestA->sendAsync();
$requestB->sendAsync();
$requestC->sendAsync();

The following examples will work

$conector = new ForgeConnector;

$requestA = new CreateForgeSiteRequest;
$requestB = new CreateForgeSiteRequest;
$requestC = new CreateForgeSiteRequest;

$connector->sendAsync($requestA)
$connector->sendAsync($requestB)
$connector->sendAsync($requestC)
$conector = new ForgeConnector;

$promises = $connector->pool([
	new CreateForgeSiteRequest,
	new CreateForgeSiteRequest,
	new CreateForgeSiteRequest,
]);

Asynchronous requests will return a PromiseInterface instead of SaloonResponse, but it will contain a response inside.

$conector = new ForgeConnector;

$requestA = new CreateForgeSiteRequest;

$promise = $connector->sendAsync($requestA);

$promise
	->then(fn (PsrResponse $response) => ...) // PsrResponse is extension of SaloonResponse
	->catch(fn (Exception) => ...)

(New) PSR Responses

Saloonā€™s response has also been updated to make it abstract, and you can now make your own response classes that accept different data. This makes it useful if in the future senders need to pass in a different object to responses.

For responses you will receive an instance of PsrResponse. This instance can be created with any class that implement PSR-7ā€™s ResponseInterface class.

The benefit of this is that it makes Saloon almost PSR-7 ready.

(New) Simulated Response

There will be a new SimulatedResponse class that will be sent back if you are using the Saloon cache plugin or a mock response. The API will be the same as the existing SaloonResponse, it will just make it easier to know if a response is real or not.

Sammyjo20 avatar Oct 30 '22 09:10 Sammyjo20

Note: I haven't looked through it all just yet, and haven't looked at the progress of the v2 branch.

I have to say, though - I'm liking many of the things I've seen, so far. The middleware pipeline is gonna be pretty sweet, as I work fairly extensively with first-class callables and invocable classes.


At the top of my head, some things I'd love to see is

  • More strongly typed code. Preferably using generics, where applicable. I've had to ignore some stuff in PHPStan, that I believe could be resolved through, say, generics. Although, I should've been able to suggest DocBlock changes, or write stubs (this is all new territory for me, though).
  • On top of this, I'd love for Saloon to primarily use interfaces, but supply default implementations (possibly splitting into traits for composability, where applicable). That would make it possible to still extend the base class (same as today), but also entirely custom implementations, that could reuse some implementation details through composability. The situation with Saloon v1 has made some parts tricky for me, but might be because I've been doing things incorrectly. (I have a tendency to think wildly differently than others, and is not directly related to Saloon, but still wanted to mention.)
  • Allow for the SaloonConnector::pool() method to accept arguments along the lines of
    1. $requests - basically either an array, as per the example in your latest message above, a \Generator generating them, or a callable that Saloon has to call in order to retrieve the aforementioned array of requests or \Generator. Possibly give the callable the SaloonConnector, or its client as argument (to more easily create async requests for the client/connector). As an inspiration, you might look into how Guzzle handles pools, as they support callable|\Generator. This is probably a bit extreme and wide typing, though. But one could always wish. šŸ™‚
      array<array-key, PendingSaloonRequest>|\Generator<PendingSaloonRequest>|(callable(): array<array-key, PendingSaloonRequest>|\Generator(PendingSaloonRequest))` $requests
      
    2. $concurrency - maximum simultaneous requests to 'keep open' at once, in case you need to send many.
      int<0, max> $concurrency
      

Regarding Promises, it might be good to research around PSR for Promises, but it appears it's kinda died out the past several years. I know Guzzle is following the Promises/A+ standard, but I've also seen other PHP HTTP libraries follow it.


I haven't been able to make the move into collaborating- or contributing to open source yet, but would give it a shot if you'd want some help (and think it'd be useful).

juse-less avatar Oct 30 '22 14:10 juse-less

Hey @bilfeldt

I'm pleased to announce that Saloon v2 will ship with full support for Laravel's HTTP Client out of the box. By default it will detect that you are using Laravel and it will use send via the HTTP client instead of using Guzzle directly. This is great because you not only get all the power of Guzzle like you did before, but now everything that uses the events for the HTTP client will work through Saloon without any extra configuration.

I think this is going to be huge for Laravel developers!

Sammyjo20 avatar Nov 04 '22 00:11 Sammyjo20

I'm pleased to announce that Saloon v2 will ship with full support for Laravel's HTTP Client out of the box. By default it will detect that you are using Laravel and it will use send via the HTTP client instead of using Guzzle directly.

Christmas came early this year šŸ„³

bilfeldt avatar Nov 04 '22 08:11 bilfeldt

Just an update everyone - I'm going to be tagging a beta release very soon - I want to fix all the broken tests now that the codebase is stable and settling down. I also want to write the docs for v2 with the first beta so you feel comfortable trying it out. This will come within the next 2-3 weeks, it would be good to have some feedback on

  • The upgrade guide
  • How v2 feels
  • Any new ideas

I'm aiming to have v2 pretty much done before the end of the year. I released v1 of Saloon last year on the 14th January so I think that would be an awesome time to release v2 šŸ‘€ I'll let you know when it's ready to test!

Sammyjo20 avatar Nov 13 '22 07:11 Sammyjo20

@Sammyjo20 seems like #101 hasn't found it's way to v2 yet!?

it returns all countries

<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
</body>
</html>

Gummibeer avatar Nov 18 '22 15:11 Gummibeer

Here's a public upgrade PR: https://github.com/Astrotomic/steam-sdk/pull/1 Besides the missing #101 feature everything seems to work.

Was a bit of "useless" renaming and importing because of changed namespaces, method names and so on. But was still a pretty fast upgrade - would say around ~15-30min without any upgrade guide but simply running pest until everything was back green. šŸ™ˆ

~And it seems like the whole MockClient thing changed or is broken - I'm on the way to debug it. But the mock client defined on my connector doesn't reach the pending request right now.~ Edit: my bad, had to drop the Laravel Saloon wrapper and because of that missed to change the container binding.

Gummibeer avatar Nov 18 '22 16:11 Gummibeer

This is awesome, thanks for sharing @Gummibeer - I am still working on the Laravel side at the moment, v2 branch will currently be very broken since the changing of namespaces.

Glad it was fairly easy to upgrade - most of my steps in the upgrade guide will explain detailed find-and-replace instructions which should fix 90% of the issues.

The other major breaking changes is the use of headers(), queryParameters(), config() and the request "data" being replaced with body(). I'm going to be working on some Saloon tonight, I'm just so excited to get v2 out there as I feel it's a real improvement while keeping all the good parts of v1, plus I've learned so much from you guys about building decent packages I really hope v2 is the one people really start using.

Sammyjo20 avatar Nov 18 '22 16:11 Sammyjo20

Accidentally I was still on the v2 branch and fixed a bug in the SDK logic. While doing so I've seen that no fixture file was persisted for a 401 Unauthorized failing request. šŸ¤” But this is absolutely right and I would like to have this fixture as well. In v1 even failed requests created a fixture file. Seems like there's a problem with fixtures if an exception is thrown.

Gummibeer avatar Nov 19 '22 19:11 Gummibeer

@Gummibeer I can't prove it right now, but I'm guessing you're using the AlwaysThrowErrors trait? If you are, that is probably the issue; in v2 - plugins are loaded first, and that plugin adds a response middleware to throw an exception - that will be added before the middleware records the response, so it's throwing the error before the fixture.

I believe this may be a v1 issue, too - would you mind testing when you get a free moment, please?

By the way I updated v2 so the bug with the URLs is now fixed šŸ„³

Edit: Perhaps we need a method to add a middleware to the top instead of adding to the bottom so internal Saloon logic could process first?

Sammyjo20 avatar Nov 23 '22 00:11 Sammyjo20

Just to let everyone know, beta is coming very soon - I had some additional final changes that I really wanted to make, I've also been focusing on writing v2's docs - as soon as I've written all the basic docs, I will publish a beta. I'd really love to get some feedback from you guys when I do publish the first one as I want to be able to make any breaking changes now before v2 is actually tagged.

Many thanks for the support so far!

Here's a sneak peak of the docs!

image

Sammyjo20 avatar Dec 01 '22 23:12 Sammyjo20

You may have noticed from the new preview image that Saloon has moved to a connector-driven design.

This was something that I can thank @Gummibeer for helping me shape up.

From version two, Saloon is going to aim to be less "magical" and also introduce less friction for the developer. One of the points I found frustrating was defining a connector class on every request that you make. This was solely so you could make a request directly without instantiating the connector, for example

$request = new UserRequest;
$response = $request->send();

This approach was very minimalist, but it introduced complexity and friction for the developer.

From version two, the connector property is being dropped entirely from the request. This means that you must send your requests through the connector like this:

$connector = new TwitterConnector;
$response = $connector->send(new UserRequest);

This allows you to have constructor arguments on the connector, perfect for API tokens or configuration. Similar to before, the request can have its own headers, config, query parameters and body but the connector will provide the very top-level defaults.

Although this is being taken out of the request, you may still add the functionality back with the HasConnector trait on the request. Although, if you add it back - you need to be aware of the downsides like not being able to have constructor arguments on your connector.

I am also introducing a new SoloRequest class which will be perfect for making just one request for API integration. With SoloRequests, you don't need a connector at all - you can define everything in the request and send it above like you used to do.

I hope these changes are great for y'all and I'm so excited to get this out!

Sammyjo20 avatar Dec 01 '22 23:12 Sammyjo20

Hey folks, Happy Holidays! ā›„ļø

Just wanted to keep everyone updated as itā€™s been a little while - Iā€™m still working on Saloon v2 and itā€™s just working through a few final bits of polish before Iā€™m happy to tag the first beta.

For me, the biggest thing is documenting the upgrade guide correctly, but recently Iā€™ve found a few fundamental changes I wanted to make, so Iā€™m going to make sure there arenā€™t any massive things stopping beta.

The great news is I think itā€™s so close and Iā€™m looking forward to hearing your feedback, just in case there is anything obvious Iā€™ve missed.

I will be taking some much needed time off over the holiday period to play video games and eat food šŸ˜‚

Thank you for a wonderful year with all the support on Saloon and I canā€™t wait to release v2, v3, v4+ in the future!

Sammyjo20 avatar Dec 21 '22 20:12 Sammyjo20

Hey @bilfeldt I have decided that instead of making the HttpSender the default sender when installing the Laravel package, you will need to enable it by overwriting the config file and changing the default sender. I feel this is better as it doesn't introduce unexpected behaviour, e.g a developer installs the package and it swaps the sender. I also have tested the GuzzleSender at great lengths and I would rather everyone using the Laravel package has a great experience and doesn't have any issues if there was a bug with just the HttpSender.

Sammyjo20 avatar Jan 02 '23 11:01 Sammyjo20

Hi, Great Job on that package!

Do you have an ETA on the beta for V2 ?

No stress though šŸ“¦ Thank you

francoisauclair911 avatar Jan 10 '23 15:01 francoisauclair911