githubEdit

πŸ”Ž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 Dumperarrow-up-right library. If you're not using Laravel and do not have it installed, you can install it below.

composer require symfony/var-dumper
circle-info

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.

$connector = new ForgeConnector;

$connector->debug()->send($request);

You can provide the die argument if you would like to terminate the application after receiving the response.

$connector->debug(die: true)->send($request);

This will provide an output in your terminal/browser like this:

Saloon Request (UserRequest) -> array:6 [
  "connector" => "Saloon\Tests\Fixtures\Connectors\TestConnector"
  "request" => "Saloon\Tests\Fixtures\Requests\UserRequest"
  "method" => "GET"
  "uri" => "https://tests.saloon.dev/api/user"
  "headers" => array:2 [
    "Host" => "tests.saloon.dev"
    "Accept" => "application/json"
  ]
  "body" => ""
]

Saloon Response (UserRequest) -> array:3 [
  "status" => 200
  "headers" => []
  "body" => "{"name":"Sam"}"
]
circle-exclamation

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