DEV Community

Zairig Imad
Zairig Imad

Posted on

11 1

Mercure (Simple Real-Time Updates)

In the past few weeks, I discovered Mercure, the first time I tested it for a POC and realized that this is the beginning of a new era in real-time application development.

I just attended Symfony Live Paris and Kévin Dunglas the creator of Mercure made a very interesting Talk about Mercure and API-Platform, I told myself it will be cool to share the tool with dev.to family, especially that Mercure is officially supported by Symfony Mercure Component.

What is Mercure?

is a 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 a reactive web and mobile apps.

Mercure

What's the Difference Between Mercure and WebSocket?

WebSocket is a low-level protocol, Mercure is a high level one. Mercure provides convenient built-in features such as authorization, re-connection, and state reconciliation; while with WebSocket, you need to implement them yourself. Also, unlike Mercure (which is built on top of HTTP and Server-Sent Events), WebSocket is not designed to leverage HTTP/2.

HTTP/2 connections are multiplexed and bidirectional by default (it was not the case of HTTP/1). When using Mercure over a h2 connection (recommended), your app can receive data through Server-Sent Events, and send data to the server with regular POST (or PUT/PATCH/DELETE) requests, with no overhead.

Basically, in most cases Mercure can be used as a modern and easier to use replacement for WebSocket

What's the Difference Between Mercure and WebSub?

WebSub is a server-to-server only protocol, while Mercure is also a server-to-client and client-to-client protocol.

Mercure has been heavily inspired by WebSub, and we tried to make the protocol as close as possible from the WebSub one.

Mercure uses Server-Sent Events to dispatch the updates, while WebSub uses POST requests. Also, Mercure has an advanced authorization mechanism and allows to subscribe to several topics with only one connection using URI templates.

I invite you to try the Demo Application and the Full Documentation in The Github Repository
https://github.com/dunglas/mercure

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more