Giter Site home page Giter Site logo

arvandhassan / companies-house-stream Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mrbrianevans/companies-house-stream

0.0 1.0 0.0 745 KB

Stream events from companies house in real time

Home Page: https://companies.stream

License: MIT License

Shell 0.14% JavaScript 0.58% TypeScript 76.58% CSS 1.11% HTML 7.80% HCL 6.70% Dockerfile 0.55% SCSS 6.55%

companies-house-stream's Introduction

Companies Stream

This project is a visualiser of changes made to the Companies House database of UK companies. It shows events as they happen in realtime, such as a new company registering, or a company going insolvent.

Companies House offers a streaming API, which sends events over a HTTPS connection.

Technology

How it works

A Docker compose application with 3 main components for the backend:

  1. A NodeJS container to listen on the Companies House streaming API and publish events to Redis ( see streamToRedis.ts).
  2. A Redis instance, mostly for facilitating Pub/Sub communication of events using Streams, and also for storing most recent timepoint to avoid missing any events.
  3. A NodeJS container which reads events from the Redis Stream and serves them as a WebSocket endpoint on /events, where each event is sent as a WebSocket message.

The frontend is "pure" in that it doesn't use a framework like React, which keeps the JS bundle really tiny and high performance. The animations are done in CSS using SASS. It is built with Vite in a Docker container, and served with Caddy (which is also a gateway to the backend endpoints and WebSocket).

To start up the whole application, clone the repository and run docker compose up -d --build in the root. You will need an env file named .api.envcontaining streaming API key(s). To run any files without Docker, build the project by installing dependencies compiling TypeScript (pnpm i && pnpm build in /server and /client). PNPM is used as the package manager, but NPM will also work (but it won't recognise the lock files).

Make your own

If you are interested in using the companies house streaming API, visit developer-specs.company-information.service.gov.uk to create an account for a free API key. The API base url is https://stream.companieshouse.gov.uk with paths /companies, /filings, /officers, persons-with-significant-control, /charges, /insolvency-cases and disqualified-officers.

Here is a minimum working example in NodeJS using the split2 package:

import split2 from 'split2' // requires `npm i split2`
import { get } from "https"

const auth = process.env.STREAM_KEY + ":"
const path = "/filings"
const options = { hostname: "stream.companieshouse.gov.uk", path, auth }
get(options, (res) => {
  if (res.statusCode === 200)
    res.pipe(split2(JSON.parse)).on("data", console.log)
  else res.pipe(process.stdout)
  res.on("end", () => console.log("Stream ended."))
}).end()

For a more complete working example of listening on a stream in NodeJS, see server/src/streams/splitStream.ts and then server/src/redis/streamToRedis.ts.

To test the streaming API from the command line with CURL, you can use the cmdline utility (after compiling):

curl --user APIKEY: -s https://stream.companieshouse.gov.uk/filings | node dist/streams/streamCmdLine.js

Questions?

If you have any questions or suggestions please open an issue on the repository, and I will get back to you.

Using this code

You are welcome to use this open source code for your own projects. See the LICENSE file for more information.

companies-house-stream's People

Contributors

mrbrianevans avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.