Mercure.rocks is a brand new protocol allowing to push data updates to web browsers and other HTTP clients in a convenient, fast, reliable and battery-efficient way. It is especially useful to publish real-time updates of resources served through web APIs, to reactive web and mobile apps.
Both Symfony and API Platform now have an official support for this protocol!
From the ground, Mercure has been designed to work with technologies not able to maintain persistent connections. It's especially relevant in serverless environments, but is also convenient when using PHP or FastCGI scripts.
Mercure is basically a higher-level replacement for WebSocket. Unlike WebSocket, it is compatible with HTTP/2 and HTTP/3.
It has been designed with hypermedia APIs in mind, is auto-discoverable through the Web Linking RFC and is also compatible with GraphQL.
It natively supports authorization, reconnection in case of network issue (with refetching of missed events), subscribing to several topics, topics patterns (using templated URIs)...
Because it is built on top of Server-sent Events and plain old HTTP requests, it is already compatible with all modern browsers, and requires 0 client-side dependencies.
The protocol is open (available as an Internet Draft), and a reference open source implementation of the server written in Go is available.—
Mercure: Push from Server to Clients
❏ Push notifications
❏ Synchronize connected devices in real-time
❏ Notify users when an async task has finished
❏ Collaborative editing (Google Drive-like)
Alternative to WebSocket, socket.io and Pusher
Today’s Use Case: Real-Time UI Updates
1. Some data is changed by a user through a form
2. UIs of all connected devices (webapp,
smartphone…) instantly display updated data
Mercure, the Protocol
❏ Built on top of SSEs and HTTP (POST)
❏ Plays well with techs not supporting persistent connections
❏ Authorization mechanism (private updates)
❏ Built-in reconnection support and retrieving of lost messages
❏ Auto-discoverable, designed for REST and GraphQL APIs
❏ Encryption support
Internet Draft: draft-dunglas-mercure
Why Server-Sent Events?
❏ Leverage HTTP/2 (WebSocket doesn’t)
❏ High-level: built-in
❏ state reconciliation
❏ Native support in modern browsers
❏ Built on top of HTTP
❏ easy to implement
❏ Pass through all firewalls
❏ Connection-less push proxies (mobile)
The Mercure Hub
❏ Implements 100% of the Mercure protocol
❏ Fast, written in Go
❏ Works everywhere: static binaries and Docker
❏ Automatic HTTP/2 and HTTPS
❏ CORS support, CSRF protection
❏ Cloud Native (12Factor App)
❏ Open source (AGPL)
Managed and on-premise version available!
The Mercure Hub
❏ Uses JSON Web Token (JWT)
❏ An update can be intended for one or several targets
❏ Publisher: must be authenticated
❏ Can be anonymous (if allowed by the config)
❏ Must be authenticated to receive updates intended for
❏ Two transports: cookie and Authorization header
Publishing or Subscribing to All Targets
❏ Set by the app server during the discovery
❏ The app server and the Mercure hub must share
the same domain (or subdomain)
❏ Supported by EventSource
❏ Recommended for web browsers