Skip to content

[12.x] Add debug() method to HTTP client for request/response logging#59124

Closed
OthmanHaba wants to merge 0 commit intolaravel:12.xfrom
OthmanHaba:12.x
Closed

[12.x] Add debug() method to HTTP client for request/response logging#59124
OthmanHaba wants to merge 0 commit intolaravel:12.xfrom
OthmanHaba:12.x

Conversation

@OthmanHaba
Copy link

Add debug() method to the HTTP client

I Came across a issue prevusly while debuging a thrid party integration that made me want to log my reqeuset and response for refrences i didn't find a built in method to provide me a full logging for the client

This PR adds a debug() method to PendingRequest that logs both the HTTP request and response in a human-readable format.

Usage

// Log to the default channel
Http::debug()->post('https://api.example.com/login', [
    'email' => 'user@example.com',
    'password' => 'secret',
]);

Log output

[2026-03-07 04:59:29] local.DEBUG: HTTP Request
── POST https://api.example.com/login ──
  Content-Type: application/json
  User-Agent: GuzzleHttp/7
  Host: api.example.com

  Body:
  {
    "email": "user@example.com",
    "password": "secret"
  }

[2026-03-07 04:59:29] local.DEBUG: HTTP Response
── 200 OK ──
  Content-Type: application/json
  Cache-Control: no-cache

  Body:
  {
    "token": "eyJ..."
  }

No breaking changes

This adds a new method to PendingRequest. No existing methods or signatures are modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants