Http
extends Http
in package
implements
HttpInterface
uses
HttpTrait
HTTP client for the NHA agent sandbox, built the same way DiscordPHP talks to `discord.com` (rate-limit buckets, driver, retry) but pointed at the NHA world API. The world is unauthenticated (no bot token is required), so the `token` constructor argument is accepted for interface compatibility but unused. A 422 response is surfaced as {@see ValidationException}.
Tags
Table of Contents
Interfaces
- HttpInterface
Constants
- BASE_URL : string = 'https://nha.recluse.lol'
- Default NHA world base URL. Override per client via the constructor (`nha_base_url` option / `NHA_BASE_URL` env), e.g. to point at a local instance; the constant stays the fallback.
- VERSION : string = '3.1.35'
- DiscordPHP-NHA version. The major tracks the NHA world API version (`openapi.json` `info.version`); minor/patch follow SemVer for this library. Sent in the `User-Agent`.
Properties
- $baseUrl : string
- The base URL every {@see Request} built here is sent against.
- $buckets : array<string|int, Bucket>
- Array of request buckets.
- $driver : DriverInterface
- HTTP driver.
- $logger : LoggerInterface
- Logger for HTTP requests.
- $loop : LoopInterface
- ReactPHP event loop.
- $promiseV3 : bool
- Whether react/promise v3 is used, if false, using v2.
- $queue : SplQueue
- Request queue to prevent API overload.
- $rateLimit : RateLimit
- The current rate-limit.
- $rateLimitReset : TimerInterface
- Timer that resets the current global rate-limit.
- $token : string
- Authentication token (unused, the NHA API is unauthenticated).
- $unboundQueue : SplQueue
- Request queue used for unbound (fire-and-forget) endpoints.
- $waiting : int
- Number of requests that are waiting for a response.
Methods
- __construct() : mixed
- Http wrapper constructor.
- getBaseUrl() : string
- The base URL requests from this client are sent against.
- getUserAgent() : string
- handleError() : Throwable
- A 422 means the NHA API rejected the request body/query as malformed or schema-mismatched — this is a bug in the request we sent, not a transient failure, so it is logged loudly and surfaced as a {@see ValidationException} rather than the generic `RequestFailedException`.
- queueRequest() : PromiseInterface
- redactTokens() : string
- Replaces the value of any `token` / `nha_token` JSON field with `***` so a response body can be logged or surfaced without leaking a live credential.
Constants
BASE_URL
Default NHA world base URL. Override per client via the constructor (`nha_base_url` option / `NHA_BASE_URL` env), e.g. to point at a local instance; the constant stays the fallback.
public
string
BASE_URL
= 'https://nha.recluse.lol'
VERSION
DiscordPHP-NHA version. The major tracks the NHA world API version (`openapi.json` `info.version`); minor/patch follow SemVer for this library. Sent in the `User-Agent`.
public
string
VERSION
= '3.1.35'
Properties
$baseUrl
The base URL every {@see Request} built here is sent against.
protected
string
$baseUrl
= self::BASE_URL
$buckets
Array of request buckets.
protected
array<string|int, Bucket>
$buckets
= []
$driver
HTTP driver.
protected
DriverInterface
$driver
$logger
Logger for HTTP requests.
protected
LoggerInterface
$logger
$loop
ReactPHP event loop.
protected
LoopInterface
$loop
$promiseV3
Whether react/promise v3 is used, if false, using v2.
protected
bool
$promiseV3
= true
$queue
Request queue to prevent API overload.
protected
SplQueue
$queue
$rateLimit
The current rate-limit.
protected
RateLimit
$rateLimit
$rateLimitReset
Timer that resets the current global rate-limit.
protected
TimerInterface
$rateLimitReset
$token
Authentication token (unused, the NHA API is unauthenticated).
protected
string
$token
$unboundQueue
Request queue used for unbound (fire-and-forget) endpoints.
protected
SplQueue
$unboundQueue
$waiting
Number of requests that are waiting for a response.
protected
int
$waiting
= 0
Methods
__construct()
Http wrapper constructor.
public
__construct(string $token, LoopInterface $loop, LoggerInterface $logger[, DriverInterface|null $driver = null ][, string $baseUrl = self::BASE_URL ]) : mixed
Parameters
- $token : string
-
Unused, kept for interface compatibility.
- $loop : LoopInterface
- $logger : LoggerInterface
- $driver : DriverInterface|null = null
- $baseUrl : string = self::BASE_URL
-
World base URL; empty falls back to self::BASE_URL.
getBaseUrl()
The base URL requests from this client are sent against.
public
getBaseUrl() : string
Return values
stringgetUserAgent()
public
getUserAgent() : string
Tags
Return values
stringhandleError()
A 422 means the NHA API rejected the request body/query as malformed or schema-mismatched — this is a bug in the request we sent, not a transient failure, so it is logged loudly and surfaced as a {@see ValidationException} rather than the generic `RequestFailedException`.
public
handleError(ResponseInterface $response) : Throwable
Parameters
- $response : ResponseInterface
Tags
Return values
ThrowablequeueRequest()
public
queueRequest(string $method, Endpoint $url, mixed $content[, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
- $method : string
- $url : Endpoint
- $content : mixed
- $headers : array<string|int, mixed> = []
Tags
Return values
PromiseInterfaceredactTokens()
Replaces the value of any `token` / `nha_token` JSON field with `***` so a response body can be logged or surfaced without leaking a live credential.
private
static redactTokens(string $body) : string
Parameters
- $body : string