Weave Code
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

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.

View on GitHub
Deep Wiki
Context7

Asynchronous HTTP client used for communication with the Discord REST API.

Frequently asked questions about Http
Can I use DiscordPHP-Http in a traditional Laravel MVC app without async workers?
No, this package is async-first and requires ReactPHP or an event loop. For synchronous Laravel apps, you’d need to wrap async responses in Promises or use Guzzle instead. It’s best suited for Laravel Octane (Swoole/Preact) or queue-based architectures.
How do I integrate this with Laravel Octane for Discord bot commands?
In Octane, initialize the HTTP client in a worker class using Swoole/Preact’s event loop. Offload Discord API calls to workers to avoid blocking sync routes. Example: `$http = new Http('token', $loop, $logger); $http->setDriver(new React($loop));` in your worker’s `handle()` method.
What Laravel versions support DiscordPHP-Http?
The package works with PHP 7.4+ and Laravel 8+ (for Octane/Swoole) or Laravel 9+ (Preact). It’s not tied to Laravel’s HTTP layer but requires async-compatible Laravel setups. Traditional MVC apps need custom async-to-sync bridges.
How do I handle rate limits with Endpoint::bind()?
Use `Endpoint::bind()` to group requests by Discord’s rate-limit buckets (e.g., `Endpoint::bind(Endpoint::CHANNEL_MESSAGE, '123', '456')`). This auto-manages buckets like `/channels/:channel` or `/guilds/:guild`. Ignoring it risks API bans for high-traffic bots.
Is there a way to use this without ReactPHP?
No, ReactPHP is a core dependency for the event loop. Alternatives like Guzzle are synchronous and lack Discord-specific optimizations. If you can’t use ReactPHP, consider wrapping Guzzle in a queue worker or using a different async library like Amp.
Can I test DiscordPHP-Http in Laravel’s PHPUnit?
Yes, but testing async code requires mocking the event loop. Use libraries like `react/promise` or `phpunit/react` to test Promises. Example: `$promise = $http->get('endpoint'); $this->assertTrue($promise->isPending());` in your tests.
What’s the performance impact of using this vs. Guzzle?
DiscordPHP-Http is faster for high-volume Discord APIs due to pre-built endpoints and rate-limit bucketing, reducing boilerplate. Guzzle adds ~10–15ms per request for manual rate-limit logic, while this package optimizes for Discord’s API structure. Benchmark with your workload.
How do I log errors in production?
Use PSR-3 logging (e.g., Monolog) with the `$logger` parameter in `Http()`. Configure Monolog’s handlers (e.g., `StreamHandler`, `SyslogHandler`) to log errors to your preferred destination. Errors in Promises are caught via `.fail()` callbacks.
Will this work with Laravel Queues for background Discord API calls?
Indirectly—you’d need to wrap the async HTTP client in a Laravel Job. The Job’s `handle()` method would initialize the event loop and process requests. Example: `new DiscordApiJob($http, $endpoint)->onQueue('discord');` with a custom queue worker.
Are there alternatives for Laravel Discord bots with less async complexity?
Yes: **Guzzle** (sync, no ReactPHP) or **Amp** (async, but requires learning Amp’s event loop). DiscordPHP-Http’s advantage is Discord-specific endpoints and rate-limit buckets, but Guzzle is simpler for teams without async experience. Weigh your need for Discord optimizations vs. ease of use.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata