Laravel Nightwatch: Log outgoing requests from Saloon
Sponsored by
unolia.comAll your domains in one place. Helps you find problems, gives you performance and security insights!
Want to sponsor this blog ?
Contact me or use
Github sponsor
Laravel Nightwatch has been released this morning, and on Unolia, we are using Saloon to make outgoing HTTP requests to our API. I wanted to log these requests in Nightwatch so I can see them in the dashboard.
To log outgoing requests from Saloon in Laravel Nightwatch, you'll need to create a custom HTTP sender that integrates Nightwatch's middleware.
Following the Saloon and Nightwatch documentation, create this new class wherever you need it, for example, in app/Http/HttpSender/LaravelSender.php
:
<?php namespace App\Http\HttpSender; use Laravel\Nightwatch\Facades\Nightwatch;use Saloon\HttpSender\HttpSender; class LaravelSender extends HttpSender{ public function __construct() { parent::__construct(); $this->handlerStack->push( Nightwatch::guzzleMiddleware() ); }}
And edit your config/saloon.php
config file and change this line:
'default_sender' => \App\Http\HttpSender\LaravelSender::class,
Simple!
This extends the Laravel Saloon HTTP sender to include the Laravel Nightwatch middleware.
Now, whenever you make an outgoing request using Saloon, it will be logged in Laravel Nightwatch.
Syntax highlighting provided by torchlight.dev