Skip to content

Commit 1b731b2

Browse files
committed
minor #11084 Real-time capabilities: add docs for the Mercure Component and Bundle (dunglas)
This PR was merged into the 4.2 branch. Discussion ---------- Real-time capabilities: add docs for the Mercure Component and Bundle Docs for https://github.com/symfony/mercure-bundle and https://github.com/symfony/mercure. Commits ------- 9c31073 Real-time capabilities: add docs for the Mercure integration
2 parents 384c2ec + 9c31073 commit 1b731b2

File tree

6 files changed

+596
-0
lines changed

6 files changed

+596
-0
lines changed

_images/mercure/chrome.png

158 KB
Loading

_images/mercure/discovery.png

173 KB
Loading

_images/mercure/schema.png

326 KB
Loading

components/mercure.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. index::
2+
single: Mercure
3+
single: Components; Mercure
4+
5+
The Mercure Component
6+
=====================
7+
8+
`Mercure`_ is an open protocol allowing to push data updates to web
9+
browsers and other HTTP clients in a convenient, fast, reliable
10+
and battery-friendly way.
11+
It is especially useful to publish real-time updates of resources served
12+
through web APIs, to reactive web and mobile apps.
13+
14+
The Mercure Component implements the "publisher" part of the Mercure Protocol.
15+
16+
Installation
17+
------------
18+
19+
.. code-block:: terminal
20+
21+
$ composer require symfony/mercure
22+
23+
Alternatively, you can clone the `<https://github.com/symfony/mercure>`_ repository.
24+
25+
.. include:: /components/require_autoload.rst.inc
26+
27+
Usage
28+
-----
29+
30+
The following example shows the component in action::
31+
32+
// change these values accordingly to your hub installation
33+
define('HUB_URL', 'https://demo.mercure.rocks/hub');
34+
define('JWT', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJmb28iLCJiYXIiXSwicHVibGlzaCI6WyJmb28iXX19.LRLvirgONK13JgacQ_VbcjySbVhkSmHy3IznH3tA9PM');
35+
36+
use Symfony\Component\Mercure\Publisher;
37+
use Symfony\Component\Mercure\Update;
38+
use Symfony\Component\Mercure\Jwt\StaticJwtProvide;
39+
40+
$publisher = new Publisher(HUB_URL, new StaticJwtProvide(JWT));
41+
// Serialize the update, and dispatch it to the hub, that will broadcast it to the clients
42+
$id = $publisher(new Update('https://example.com/books/1.jsonld', 'Hi from Symfony!', ['target1', 'target2']));
43+
44+
Read the full :doc:`Mercure integration documentation </mercure>` to learn
45+
about all the features of this component and its integration with the Symfony
46+
framework.
47+
48+
.. _`Mercure`: https://mercure.rocks

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Topics
4141
frontend
4242
http_cache
4343
logging
44+
mercure
4445
messenger
4546
performance
4647
profiler

0 commit comments

Comments
 (0)