Skip to content

LibHttp

ImperaZim edited this page Jun 30, 2026 · 4 revisions

LibHttp

LibHttp is the official HTTP helper library for EasyLibrary 3.x.

Identity

Field Value
Package id libhttp
Plugin name LibHttp
Namespace imperazim\http
Type classpath package
Repository https://github.com/ImperaZim/LibHttp
Required package libcommons

What It Provides

  • immutable HTTP request and response objects;
  • cURL transport with PHP stream fallback;
  • retry policies for transient network/status failures;
  • auth header helpers for bearer token, basic auth and API-key headers;
  • lightweight request/response interceptors for default headers, request mutation and response observation;
  • local fixed-window rate limiting with an injectable clock for tests;
  • typed exceptions for transport, status, JSON and download failures;
  • JSON request and response helpers;
  • atomic downloads with optional max-size and SHA-256 checks;
  • generic webhook helpers and Discord webhook payload builders;
  • PMMP async task adapter for request callbacks.

LibHttp uses LibCommons for generic JSON, URL validation, SHA-256 and atomic filesystem helpers. HTTP request/response, retry, transport, webhook and download contracts remain owned by LibHttp.

Common Patterns

Bearer token request:

use imperazim\http\auth\HttpAuth;
use imperazim\http\HttpRequest;

$request = HttpRequest::get('https://example.com/api/private')
    ->withHeaders(HttpAuth::bearerToken($token));

Default headers and local throttling:

use imperazim\http\client\HttpClient;
use imperazim\http\interceptor\DefaultHeadersInterceptor;
use imperazim\http\rate\FixedWindowRateLimiter;

$client = new HttpClient(
    interceptors: [new DefaultHeadersInterceptor(['User-Agent' => 'MyPlugin/1.0'])],
    rateLimiter: FixedWindowRateLimiter::perSecond(5)
);

Typed failures:

use imperazim\http\exception\StatusHttpException;
use imperazim\http\exception\TransportHttpException;

try {
    $client->sendOrFail($request);
} catch (TransportHttpException) {
    // Connection, DNS, timeout or TLS failure.
} catch (StatusHttpException $error) {
    $status = $error->getResponse()->getStatusCode();
}

Install As Package

/easylibrary packages install libhttp development confirm

Restart, then validate:

/easylibrary packages status libhttp
/elprobe libhttp
/elprobe run libhttp

Install As Standalone

Download LibHttp-1.0.0-dev.phar from the GitHub Release and place it under plugins/, then restart the server.

Notes

LibHttp replaces the old idea of keeping HTTP/download/webhook helpers inside the EasyLibrary core. The core can still perform its own private package downloads, but public plugin-facing HTTP helpers belong here.

Examples

Use the repository examples when you want copyable code instead of API lists:

The examples are linted by the LibHttp quality workflow so docs and public API usage stay aligned.

Clone this wiki locally