Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Http Adapter Bundle Laravel Package

ottsch/http-adapter-bundle

A Symfony bundle for integrating configurable HTTP adapters, making it easy to send HTTP requests through dependency-injected client services. It centralizes adapter configuration and simplifies HTTP transport setup in Symfony applications.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install the fork: composer require ottsch/http-adapter-bundle. It keeps the original Widop\... namespaces, so register Widop\Bundle\HttpAdapterBundle\WidopHttpAdapterBundle in config/bundles.php (or AppKernel::registerBundles()).
  • Minimal configuration — the adapter backend is the only real knob:
# config/packages/widop_http_adapter.yaml
widop_http_adapter:
    adapter: curl   # or "stream"
  • The bundle exposes widop.http.adapter, an instance of Widop\HttpAdapter\HttpAdapterInterface. Type-hint the interface, not the concrete class.
  • First use case — a single GET from a command or service:
$response = $adapter->get('https://api.example.com/v1/status', [
    'Accept: application/json',
]);

if ($response->getStatusCode() === 200) {
    $data = json_decode($response->getBody(), true);
}
  • Where to look first: DependencyInjection/Configuration.php in the bundle (it confirms the only config is the adapter choice), then the vendor widop/http-adapter source for the exact HttpAdapterInterface and HttpResponse signatures. Do not guess the method signatures from memory — the library predates PSR-18 and its conventions are non-standard.

Implementation Patterns

  • Wrap it in an application client. Never inject the adapter into controllers or commands directly; centralize URL building, auth headers, error mapping, and decoding in one class.
final class AcmeApiClient
{
    public function __construct(
        private HttpAdapterInterface $adapter,
        private string $token,
    ) {}

    public function fetchUser(int $id): array
    {
        $response = $this->adapter->get(
            sprintf('https://api.acme.test/users/%d', $id),
            ['Accept: application/json', 'Authorization: Bearer '.$this->token]
        );

        if ($response->getStatusCode() >= 400) {
            throw new AcmeApiException($response->getStatusCode(), $response->getBody());
        }

        return json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
    }
}
services:
    App\Http\AcmeApiClient:
        arguments: ['@widop.http.adapter', '%env(ACME_TOKEN)%']
  • POST/PUT/PATCH: the adapter does no encoding. Serialize yourself and pass the body as the third argument:
$response = $adapter->post(
    'https://api.acme.test/users',
    ['Content-Type: application/json', 'Accept: application/json'],
    json_encode(['name' => 'Ada'], JSON_THROW_ON_ERROR)
);
  • Retries: the package has none. Either wrap the adapter in a decorator implementing HttpAdapterInterface (remember it has six methods: get, head, post, put, patch, delete), or retry around a single call inside the domain client — the latter is simpler and usually preferable.
  • Testing: type-hint Widop\HttpAdapter\HttpAdapterInterface and use a hand-written fake that returns Widop\HttpAdapter\HttpResponse instances. Verify the constructor argument order against your installed version before relying on it in tests.
  • Good fit workloads: webhook delivery, health probes, cache warmup, small third-party API calls in command/worker context. Keep it out of the request/response hot path for slow external calls.
  • Observability decorator: add a logging decorator (method, URL, status, duration) rather than sprinkling error_log at call sites.

Gotchas and Tips

  • Effectively unmaintained (2019, zero dependents, no PSR-18/PSR-7 bridge). For new code use symfony/http-client. Reach for this only in a legacy codebase that already depends on it.
  • Adapter choice is the only configuration. No timeout, proxy, TLS, retry, or base-URI settings exposed via YAML. The cURL adapter spins up a handle per call with library defaults, so you inherit timeouts you cannot tune through config. Fork the adapter or swap the service if you need control.
  • stream adapter requires allow_url_fopen=1 and respects default_socket_timeout; it is slower and less featureful. Use curl in production unless the extension is unavailable.
  • Header format is pass-through. Use "Name: value" strings, not associative arrays, and set Accept/Content-Type yourself — do not assume defaults.
  • HTTP errors are returned, not thrown (confirm on your version). Always check getStatusCode(). Transport-level failures throw Widop\HttpAdapter\HttpAdapterException — catch around every call.
  • Response API is thin: getBody(), getHeaders(), getStatusCode(). Header parsing for Content-Type, Location, and pagination links is your responsibility.
  • No JSON handling. Decode manually and guard against malformed payloads.
  • Debugging is bare. There is no built-in logging; reproduce with curl -v using the same URL and headers, or add the decorator described above.
  • Cleanest extension point: override the widop.http.adapter service definition/alias in your own service config with a custom HttpAdapterInterface implementation (timeouts, retries, logging) — call sites stay untouched.
  • Fork trap: the ottsch fork retains Widop\... namespaces and the widop_http_adapter config root. Do not also composer require widop/http-adapter separately, or you risk duplicate class definitions.
  • PHP version drift: this is 2019-era code. Expect strict-type and return-type friction on PHP 8+, and run your test suite after any runtime upgrade.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib