twitchphp / http
Non-blocking HTTP client and OAuth2 helper for the Twitch Helix API, on ReactPHP.
dev-main
2026-09-09 15:44 UTC
Requires
- php: ^8.1
- psr/http-message: ^1.1 || ^2.0
- psr/log: ^1.1 || ^2.0 || ^3.0
- react/event-loop: ^1.5
- react/http: ^1.11
- react/promise: ^3.2 || ^2.11
- react/socket: ^1.16
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpunit/phpunit: ^10.5 || ^9.6
- react/async: ^4.3 || ^3.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-09 15:44:13 UTC
README
Non-blocking HTTP client and OAuth2 helper for the Twitch Helix API,
built on ReactPHP. It is the transport layer used by
TwitchPHP — the same split as
discord-php/http under DiscordPHP — and is usable on its own.
- Every call gets the
Authorization: BearerandClient-Idheaders Twitch requires. - A bounded concurrency queue, automatic
429handling (honouringRatelimit-Reset), and transient5xxretry with backoff. - Typed exceptions (
InvalidTokenException,NoPermissionsException,RateLimitException, …). Twitch\Http\OAuthcovers the client-credentials, authorization-code, refresh, and device-code flows, plusvalidate/revoke.
Install
composer require twitchphp/http
Requires PHP 8.1+.
Usage
use React\EventLoop\Loop; use Twitch\Http\Endpoint; use Twitch\Http\Http; use Twitch\Http\OAuth; $loop = Loop::get(); $oauth = new OAuth('client-id', 'client-secret', $loop); $oauth->clientCredentials()->then(function (array $token) use ($loop) { $http = Http::create($token['access_token'], 'client-id', null, $loop); // GET https://api.twitch.tv/helix/users?login=twitchdev $http->get( (new Endpoint(Endpoint::USERS))->addQuery('login', 'twitchdev') )->then(function (?array $body) { // $body === ['data' => [[...user...]], 'pagination' => []] print_r($body['data'][0]); }); }); $loop->run();
Http resolves with the decoded JSON body untouched — Twitch's
{ "data": [...], "pagination": { "cursor": "..." } } envelope is passed
straight through, and a 204 resolves with null. Higher-level unwrapping,
Parts, repositories and events live in TwitchPHP.
License
MIT — see LICENSE.