discord-php/http
Async PHP HTTP client for the Discord REST API (PHP 7.4+). Works with an event loop (e.g., React) and PSR-3 logging. Provides get/post/put/patch/delete plus queueRequest, returns decoded JSON promises, and includes Endpoint constants with bind() for rate-limit buckets.
Endpoint::bind()) ensures compliance with Discord’s rate limits, critical for scalable bots (e.g., moderation tools, gaming platforms).Endpoint::* constants simplify URL construction and rate-limit bucketing, reducing errors in dynamic routes.DiscordHttpService) for seamless integration.done, fail). Mitigation: Extend with custom middleware (e.g., logging, retries) using PSR-15.discord-php/discord.php for WebSocket needs (e.g., presence updates).Async Infrastructure Readiness:
Rate-Limit Requirements:
Endpoint::bind() is mandatory to avoid throttling.Discord API Scope:
discord-php/discord.php).Laravel Integration Depth:
Error Handling Needs:
PHP Version Constraints:
Long-Term Maintenance:
monolog/monolog.Assess Async Readiness:
Set Up Async Infrastructure:
composer require discord-php/http reactphp/react
php artisan queue:work).Wrap the Package:
// app/Services/DiscordHttpService.php
class DiscordHttpService {
public function __construct() {
$loop = \React\EventLoop\Factory::create();
$logger = new Logger('discord');
$this->http = new \Discord\Http\Http('Bot TOKEN', $loop, $logger);
$this->http->setDriver(new \Discord\Http\Drivers\React($loop));
}
public function get(string $endpoint, array $params = []) {
$url = \Discord\Endpoint::bind($endpoint, ...$params);
return $this->http->get($url);
}
}
AppServiceProvider.Replace Synchronous Calls:
// Before (synchronous)
$response = Http::get('https://discord.com/api/users/@me');
// After (async)
$service->get(\Discord\Endpoint::CURRENT_USER)
->done(fn($response) => logger()->info($response))
->fail(fn($e) => logger()->error($e->getMessage()));
Handle Promises:
now() or ReactPHP promises for async workflows:
$service->get(\Discord\Endpoint::CHANNEL_MESSAGES, $channelId)
->then(fn($messages) => Message::upsert($messages))
->otherwise(fn($e) => report($e));
Rate-Limit Optimization:
Endpoint::bind() for correct bucketing:
$endpoint = \Discord\Endpoint::bind(
\Discord\Endpoint::CHANNEL_MESSAGE,
$channelId,
$messageId
);
Phase 1: Infrastructure Setup (1–2 Sprints)
Phase 2: Core Integration (2–3 Sprints)
Endpoint::bind()).Phase 3: Async Workflows (1–2 Sprints)
Phase 4: Advanced Features (Ongoing)
How can I help you explore Laravel packages today?