Hello,
What is the best way to store a “bookmark/position” when following a stream over the HTTP API?
What I am planning to do is this:
- Read the batch of events (with long poll) using the URL stored in step 3. If not available - start with /streams/app-events/0/forward/5?embed=body.
- Process the events.
- Get the previous link and store it in the local DB. At this point, the process can quit and start again.
- Repeat from step 1.
There are two annoyances with this approach:
- all links returned do not include the embed=body query string of the initial request meaning the app needs to amend the stored URL to add the query string;
- the URL stored include IP or host - so if we were to change it then the “bookmark” would essentially become invalid.
The options I can see are:
- Store the link[rel=‘previous’] (as described above); append embed=body when requesting.
- Strip the hostname from link[rel=‘previous’] and store it; use hostname from the app’s configuration and append embed=body when requesting.
- Extract the position value from link[rel=‘previous’] and store as a number; construct full URL when requesting.
- Use the max(positionEventNumber) of all events, store it and construct the full URL when requesting.
All have pros and cons. I believe the documentation recommends option one.
I want to avoid storing the hostname as a reference out of all, leaning towards option 2.
But what are people’s thoughts?
Cheers.