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 Laravel Package

teamones/http

Teamones HTTP is a Laravel/PHP package that provides a simple HTTP client API for making requests and handling responses. It aims to streamline common HTTP operations in Laravel applications with a lightweight, developer-friendly interface.

View on GitHub
Deep Wiki
Context7

Getting Started

teamones/http is a thin wrapper around yurunsoft/yurun-http aimed at Laravel/teamones applications. It gives you a fluent, container-friendly HTTP client without reimplementing YurunHttp's parser, cookie jar, or connection pool.

  1. Install via Composer:
    composer require teamones/http
    
  2. If the package ships a service provider, register it (Laravel 5.5+ auto-discovers it; otherwise add it to config/app.php providers). Then publish any config:
    php artisan vendor:publish --provider="Teamones\Http\ServiceProvider"
    
    Look for config/http.php (or similarly named) — that's where base URI, default headers, and timeout settings usually live.
  3. Check the entry point in src/. You'll typically find an Http class (the fluent client) and a Facade that proxies to it. That class is what you'll inject or resolve from the container.

First use case — call a JSON API from a controller or service:

use Teamones\Http\Http;

$client = app(Http::class);
$response = $client->get('https://api.example.com/users');

if ($response->getStatusCode() === 200) {
    $data = $response->json(); // YurunHttp returns a decoded array
}

If a facade is registered, \Teamones\Http\Facade::get(...) works the same way. Confirm the alias in the provider before relying on it.

Implementation Patterns

Constructor-style configuration for reusable clients. Don't rebuild the client on every call. Bind a configured instance in a service provider:

$this->app->singleton('api.client', function () {
    return (new Http())
        ->setTimeout(5, 10)          // YurunHttp: connect, total
        ->withHeaders(['Accept' => 'application/json']);
});

Then inject it where needed. This keeps the connection pool and cookie jar warm — important if you're running under Swoole.

Fluent chaining for per-request overrides. The wrapper follows YurunHttp's mutable-builder style. Clone when you need a one-off:

$response = (clone $client)
    ->withHeaders(['X-Request-Id' => $id])
    ->withOptions(['verify' => false])
    ->post($url, ['name' => 'foo']);

JSON in, JSON out. YurunHttp auto-decodes JSON based on the Content-Type response header. Pass arrays as the body and they'll be sent as form-encoded by default; force JSON explicitly:

$client->withHeaders(['Content-Type' => 'application/json'])
       ->post($url, json_encode($payload));

Or, if the wrapper exposes a json() helper, prefer it — it sets the header and encodes for you.

Cookie handling across a session. YurunHttp maintains a cookie jar on the client object. Authenticate once, reuse the same instance for the rest of the request lifecycle:

$client->post($base.'/login', $creds);
$profile = $client->get($base.'/me')->json();

This is a good fit for scraping flows or legacy session-based APIs, but a bad fit for long-lived singletons if you need per-user isolation — see gotchas.

Retries and circuit-breaker-ish helpers. Wrap calls in a small retry helper rather than chaining:

private function request(callable $fn, int $tries = 3)
{
    for ($i = 0; $i < $tries; $i++) {
        try {
            $res = $fn();
            if ($res->getStatusCode() < 500) return $res;
        } catch (\Throwable $e) {
            if ($i === $tries - 1) throw $e;
        }
        usleep(100_000 * ($i + 1));
    }
}

Testing. Because the wrapper defers to YurunHttp, the easiest path is to inject a fake client or bind a stub into the container in your test setup. Avoid hitting the network in feature tests — mock the Http instance with a response stub that returns your fixture payload from json().

Gotchas and Tips

  • 4xx/5xx do not throw by default. YurunHttp returns a populated response object regardless of status. Always check $response->getStatusCode() before trusting json(). If the wrapper adds an exception layer, verify whether it's opt-in or default.
  • getBody() is a stream, not a string in all cases. In YurunHttp the body is available via getBody() as a string buffer, but if you're consuming large responses or using Swoole coroutines, call ->getBody() once and cache the result — the stream position may be exhausted on repeated reads.
  • Swoole coroutine safety. Under Swoole, do not share a single Http instance across concurrent coroutines. The cookie jar and connection pool are bound to the instance. Use clone per coroutine or rely on the pool-safe factory methods YurunHttp provides (HttpRequest::make() semantics, if exposed).
  • Timeouts default to YurunHttp values (often generous). Set both connect and total timeouts explicitly — an unconfigured client in a queue worker can hang for minutes.
  • SSL verification is on by default. Turning it off (verify => false) is common in local dev but easy to leak into production. Gate it behind app()->environment('local'), not a config flag someone enables "temporarily."
  • Cookie jar persistence surprises. A singleton client accumulates cookies across requests — fine for scraping, wrong for a multi-tenant API where each tenant needs its own session. Use clone or a fresh instance per tenant.
  • Proxy and custom CA certs are configured through the underlying YurunHttp options (proxy, cert, ssl_key). If the wrapper exposes withOptions(), that's your escape hatch to anything the wrapper doesn't surface.
  • Debugging. YurunHttp's HttpResponse exposes headers (getHeaders()), status, and body. For wire-level debugging, wrap in try/catch and log the raw body before json_decode — JSON errors often come from a 200-response HTML error page, not the endpoint itself.
  • Extension points. The wrapper's value is small; when you need connection pooling, HTTP/2, or chunked uploads, drop down to HttpRequest directly. Don't fight the wrapper — it's an ergonomic layer, not a full abstraction, and it's fine to mix both in the same codebase.
  • Zero dependents / low star count means limited community coverage. Skim src/ and composer.json before adopting — check the pinned YurunHttp version, since behavior (especially JSON auto-decode and cookie defaults) has shifted across major versions.
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