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.
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.
composer require teamones/http
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.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.
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().
$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.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).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."clone or a fresh instance per tenant.proxy, cert, ssl_key). If the wrapper exposes withOptions(), that's your escape hatch to anything the wrapper doesn't surface.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.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.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.How can I help you explore Laravel packages today?