restfeed-server-java
Library to provide a REST Feed server endpoint in Java.
The library is written in pure Java and has no transitive dependencies.
Usage
Add this library to your pom.xml
:
<dependency>
<groupId>org.restfeeds</groupId>
<artifactId>restfeed-server</artifactId>
<version>0.0.2</version>
</dependency>
Spring Boot
Use this library when using Spring Boot:
Feel free to implement the server endpoint in a framework of your choice, such as Java EE, Quarkus, Kotlin, Spring Webflux, etc.
Further examples are highly appreciated.
Components
RestFeedEndpoint
This is the core class that handles long polling.
FeedItemRepository
You need to implement a FeedItemRepository with the database of your choice.
Feed items are stored in a repository in chronological order of addition. An SQL database is a good choice, as it provides auto incrementation of primary keys. A single partitioned Kafka topic may also be reasonable as repository, but it requires more custom client and offset handling.
Provide access to the database that stores the feed items.
Consider a good primary key that identifies a feed item and guarantees the chronological sequence of addition to the feed. An auto-incrementing database sequence is a good choice.
FeedItem
Java bean representing the data model of the returned feed items.
HTTP endpoint
You need to implement a GET endpoint in a HTTP framework of your choice.
This endpoint must call the RestFeedEndpoint#fetch
method and pass the item offset and the page limit. The endpoint must support the next
link.
This endpoint must support content negotiation.
NextLinkBuilder
You need to implement a NextLinkBuilder to point to your REST endpoint.
The next
link must provide access to all subsequent feed items. The next link response must not include the current feed item(s).
It is up to the implementation, how this link is build and evaluated.