Details

Language / Topic
phpPHP
Category
Libraries
Source
guzzle

Rules

balanced
- Create a Guzzle client with `base_uri` and default options — reuse the client instance for connection pooling.
- Use middleware stack for auth tokens, logging, and retry logic — add with `HandlerStack::create()` and `$stack->push()`.
- Handle `RequestException` for HTTP errors and `ConnectException` for network failures — check `$e->hasResponse()` before accessing the response.
- Use `RequestException` handling: `try { ... } catch (RequestException $e) { $e->getResponse() }`.
- Use `json` option for JSON request bodies, `form_params` for form-encoded data.
- Use middleware stack for request/response manipulation: auth, logging, retry.
- Use `HandlerStack::create()` with `Middleware::retry()` for automatic retry on transient failures.