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

This package is auto-updated.

Last update: 2024-04-21 13:10:55 UTC


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

http://server.com/inventory?lastEvenetId=1223

LongPolling

http://server.com/inventory?timeout=5

http://server.com/inventory?lastEvenetId=1223&timeout=5