Stream is HTTP request or WebSocket connection

Hi friends, can you please help me to understand exactly if the CH Stream is a simple get HTTP request or if it’s a WebSocket connection?

Thanks in advance!

I believe it’s just http. There is no mention of use of the HTTP Upgrade header to upgrade this to a websocket. (And indeed no mention of websockets in general).

According to the CH Streaming API documentation:

Connecting to a streaming endpoint

Establishing a connection to the streaming APIs involves making a long-running HTTP request, and incrementally processing each response line. Conceptually, you can think of this as downloading an infinitely long file over HTTP.

Connecting

Create an HTTP connection using a recent HTTP client library, and consume the streaming data for as long as possible. Repeatedly connecting and disconnecting is a resource expensive operation, and you may be rate-limited if you frequently reconnect.

Our servers will maintain the connection indefinitely, only dropping it in the event of high network congestion, routine maintenance, server errors or too many connections from an application.

Keeping a connection alive

HTTP connections will typically be timed out and disconnected by clients if there is no data transfer for a while. To avoid this and keep a connection alive when there is no new data to stream, the streaming API periodically sends an empty record as a heartbeat. These take the form of a blank line within the streamed feed, and must be ignored by client applications.

Hope this helps.

1 Like

Thanks a lot @voracityemail I will check

Yes it is just a plain HTTP(s) endpoint, no websocket support.

If you’re familiar with javascript, see this example on GitHub:

It just sends an authenticated GET request to the endpoint and parses the response as JSON lines.

I’ve written a little bit about the streams pattern here: HTTP streams | CH Guide but do let me know if anythings not clear, I’ll happily add some more detail.

1 Like

Hi @ebrian101 , thanks for your quick reply, it’s clear now!

I try the stream API call on the postman like a simple HTTP get to request the connection is done and the status is 200 but it keeps running and no response comes up!!!
The same thing is happening whenever I try to do a call from my Flutter app the connection is done but the response never comes up!
Are you know the issue or if you know how to run it on Postman so I get the idea,By the way, I’m able to run it in Chrome using custom Authorization extension

Any help will be appreciated!!

Thanks

Yes you can run it on postman.
Request the URL https://stream.companieshouse.gov.uk/filings. Set authorisation to “Basic auth” with your username as your api key and password empty.
Make the request and wait for some events to come through. It could take a few minutes for events to start coming through so be patient. This depends on how busy the stream is when you connect.
You can use https://companies.stream to see how many events are currently coming through on any of the streams. The filings one is the busiest so I suggest using that one for testing.

1 Like

@ebrian101 Thanks a lot for your help, I really appreciate it :wink:

I tried on the Postman and wait for 30 minutes nothing comes up, but at the same time, the responses came in the https://companies.stream, is that possible for you to send any Postman collection that is worked for streams? Thanks in advance!

This postman request is working for me:

Obviously swap the username field for your own API key.

After about 30 seconds:

URL is https://stream.companieshouse.gov.uk/filings

1 Like