From 896f67ecdc16e38d4301b56692f3a95fa1e0746b Mon Sep 17 00:00:00 2001 From: Umputun Date: Tue, 18 Jun 2019 12:58:50 -0500 Subject: [PATCH] add info and SSE streams and response example to readme --- README.md | 35 ++++++++++++++++++++++-- backend/app/rest/api/rest_public_test.go | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index db47d40e..1502bc8d 100644 --- a/README.md +++ b/README.md @@ -628,8 +628,39 @@ Sort can be `time`, `active` or `score`. Supported sort order with prefix -/+, i ### Streaming API -* `GET /api/v1/stream/info?site=site-idd&url=post-url` - returns stream with `PostInfo` records ("\n" separated) for the site and url` -* `GET /api/v1/stream/last?site=site-id` - returns updates stream with comments ("\n" separated) for the site` +Streaming API provide server-sent events for post updates as well as site update + +* `GET /api/v1/stream/info?site=site-idd&url=post-url` - returns stream (`event: info`) with `PostInfo` records for the site and url` +* `GET /api/v1/stream/last?site=site-id` - returns updates stream (`event: last`) with comments for the site` + +
response example + +``` +data: {"url":"https://radio-t.com/blah1","count":2,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.142872-05:00"} + +event: info +data: {"url":"https://radio-t.com/blah1","count":3,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.157709-05:00"} + +event: info +data: {"url":"https://radio-t.com/blah1","count":4,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.172991-05:00"} + +event: info +data: {"url":"https://radio-t.com/blah1","count":5,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.188429-05:00"} + +event: info +data: {"url":"https://radio-t.com/blah1","count":6,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.204742-05:00"} + +event: info +data: {"url":"https://radio-t.com/blah1","count":7,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.220692-05:00"} + +event: info +data: {"url":"https://radio-t.com/blah1","count":8,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.23817-05:00"} + +event: info +data: {"url":"https://radio-t.com/blah1","count":9,"first_time":"2019-06-18T12:53:48.125686-05:00","last_time":"2019-06-18T12:53:48.254669-05:00"} +``` + +
### RSS feeds diff --git a/backend/app/rest/api/rest_public_test.go b/backend/app/rest/api/rest_public_test.go index 03aa69e5..c62b62f5 100644 --- a/backend/app/rest/api/rest_public_test.go +++ b/backend/app/rest/api/rest_public_test.go @@ -741,7 +741,7 @@ func TestRest_LastCommentsStream(t *testing.T) { recs := strings.Split(strings.TrimSuffix(string(body), "\n"), "\n") require.Equal(t, 9*3, len(recs), "9 events") - t.Logf("%v", recs) + t.Logf("%s", string(body)) assert.True(t, strings.Contains(recs[1], `test 123`), recs[1]) }