Mercure-Hub: How Mercure-hub works
This documentation is part of the Getting started guide. View the full guide here: How to get started with Mercure-hub.
👋 Welcome to the Stackhero documentation!
Stackhero provides a fully managed Mercure-Hub cloud service designed to make real-time data delivery simple and reliable. You get:
- Unlimited requests and message sizes for complete flexibility.
- A custom domain with built-in HTTPS security (for example, https://real-time.your-company.com).
- Effortless one-click updates to keep your hub up to date with zero hassle.
- High performance and strong security on a private, dedicated infrastructure.
- Multiple regions: 🇪🇺 Europe and 🇺🇸 USA for low-latency delivery.
Get up and running fast: it takes just 5 minutes to launch your Mercure-Hub cloud hosting environment and start pushing real-time updates to your applications.
Consider a scenario where a customer is viewing a book with the ID 1.
On the front end, you subscribe to the topic /books/1 on Mercure-hub using the Server-Sent Events (SSE) API, a native HTML5 feature. With around 10 lines of JavaScript code and no need for external libraries, this approach remains both straightforward and efficient.
On the back end, when a book is purchased, you send an HTTP request to Mercure-hub to update the stock. For instance, if there are 7 books with the ID 1 and a user buys one, the updated stock becomes 6.
Your back end sends { stockCount: 6 } to the topic /books/1 on Mercure-hub so that every user viewing that book instantly receives the updated stock count. This process requires only an HTTP request from the back end and just a few lines of code on the front end.
This principle can be used to push data from the server to the client, between clients, or even between servers.