πDebugging
While building API integrations, sometimes you will send a request and the API will return an error. This could be due to sending the request badly or incorrect data. Sometimes debugging the request can be difficult - so Saloon has some helpers to resolve this.
Prerequisites
Saloon's default debugging driver uses Symfony's Var Dumper library. If you're not using Laravel and do not have it installed, you can install it below.
Laravel already includes this library.
Debugging Request & Response
The simplest way to debug a request and response is to use the debug()
method on your connector before sending a request. This will output an easy-to-understand array of the request and the response.
You can provide the die
argument if you would like to terminate the application after receiving the response.
This will provide an output in your terminal/browser like this:
This output will show the request just before it is sent to the sender. If the sender (like Guzzle) adds any additional headers or changes the request, these changes will not be displayed.
Separate Debuggers
You may also use debugRequest
and debugResponse
independently if you would like to debug just the request or response respectively.
Custom Debugger Handlers
You may also provide a closure to the debugRequest
and debugResponse
methods if you would like to write your own debugging implementations.
Last updated