mercure_client 1.0.0 copy "mercure_client: ^1.0.0" to clipboard
mercure_client: ^1.0.0 copied to clipboard

outdated

Provide a quick way to publish and consume messages on Mercure

example/mercure_client_example.dart

import 'dart:convert';

import 'package:mercure_client/mercure_client.dart';

Future<void> main() async {
  final books = <Book>[];

  final mercure = Mercure(
    url: 'http://example.com/.well-known/mercure', // your mercure hub url
    topics: ['/books/{id}'], // your mercure topic
    token: 'your_jwt_token', // Bearer authorization
    lastEventId: 'last_event_id', // in case your stored last recieved event
  );

  /// Subscribe to mercure hub
  await for (final event in mercure) {
    books.add(Book.fromJson(json.decode(event.data) as Map<String, dynamic>));
  }
}

class Book {
  Book._(this.id, this.title);

  factory Book.fromJson(Map<String, dynamic> json) {
    return Book._(
      json['id'] as int,
      json['title'] as String,
    );
  }

  final int id;
  final String title;

  Map<String, dynamic> toJson() => <String, dynamic>{'id': id, 'title': title};
}
12
likes
0
points
221
downloads

Publisher

verified publisherherve-guigoz.com

Weekly Downloads

Provide a quick way to publish and consume messages on Mercure

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http

More

Packages that depend on mercure_client