Source: juststeveking-uk-astro.pages.dev

Embracing PSRs to build an interoperable Http Client
Recently I have been scratching my head over PSR-18. As a new PSR there isn’t a lot of information around it, but I saw that as a challenge. I decided to accept this challenge and build a compliant HTTP client to embrace the future of interoperability.

namespace JustSteveKing\HttpSlim; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Client\ClientExceptionInterface; class HttpClient implements HttpClientInterface { protected ClientInterface $client; protected StreamFactoryInterface $streamFactory; protected RequestFactoryInterface $requestFactory; }

final protected function __construct( ClientInterface $client, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory ) { $this->client = $client; $this->requestFactory = $requestFactory; $this->streamFactory = $streamFactory; } public static function build( ClientInterface $client, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory ): self { return new static( $client, $requestFactory, $streamFactory ); }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Community Partners