bzrk / http-feeds-server
This project is a PHP Implementation of [HTTP Feeds] (https://github.com/http-feeds/http-feeds).
0.6
2022-02-13 15:34 UTC
Requires
- php: >=8
- ext-json: *
- bzrk/php-stream: ^0.10.0
- bzrk/php-timeunit: ^0.3.0
- psr/http-message: ^1.0
- psr/log: ^3.0
- ringcentral/psr7: ^1.3
- webmozart/assert: ^1.10
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.6
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.5
README
This project is a PHP Implementation of [HTTP Feeds] (https://github.com/http-feeds/http-feeds).
HTTP Feeds
Asynchronous event streaming and data replication with plain HTTP APIs.
HTTP feeds is a minimal specification for polling events over HTTP:
- An HTTP feed provides a HTTP GET endpoint
- that returns a chronological sequence (!) of events
- serialized in CloudEvents event format
- in batched responses using the media type
application/cloudevents-batch+json
- and respects the
lastEventId
query parameter to scroll through further items- to support infinite polling for real-time feed subscriptions.
HTTP feeds can be used to decouple systems asynchronously without message brokers, such as Kafka or RabbitMQ.
Install
composer require bzrk/http-feeds-server
Usage with Slim
... class Repo implements Repository { public function getByIdGreaterThan(string $lastEventId, int $limit): FeedItemCollection { .... } } $fetcher = HttpFeedsFetcher::builder(new Repo())->limit(10)->build(); $app = AppFactory::create(); $app->get('/', new HttpFeedsController($fetcher)); $app->addErrorMiddleware(true, true, true); $app->run();
Usage with ReactPHP
... class Repo implements Repository { public function getByIdGreaterThan(string $lastEventId, int $limit): FeedItemCollection { .... } } $fetcher = HttpFeedsFetcher::builder(new Repo())->limit(10)->build(); $http = new React\Http\HttpServer(new HttpFeedsController($fetcher)); $socket = new React\Socket\SocketServer('0.0.0.0:8080'); $http->listen($socket);
Parameters
Name | Type | Description |
---|---|---|
lastEventId | String | last processing eventid from client |
timeout | Integer | enable long polling with specified timeout in seconds |
Examples
Polling
http://server.com/inventory?lastEvenetId=1223
LongPolling