FLUTTER ECOSYSTEM

pratikbaid3/flutter_client_sse

Pacote Dart para ajudar a consumir a API SSE. Consome eventos enviados pelo servidor retornando um modelo analisado do evento, id e dados

Capa do projeto flutter_client_sse
Stars
54
Forks
74
Último push (UTC)
22 de mar. de 2025
Status do projeto
Ativo
Pratik Baid GitHub avatar
GITHUB User

Pratik Baid ↗

GSoC 21' @CCExtractor | SIH 2020 Winner | SDE | Founder @Hustle-Creatives

Hustle CreativesIndia
LinguagensDartTypeScript

Pacotes publicados por este repositório

Dependências usadas

Lista de dependências 3 itens
  • flutter{"sdk":"flutter"}
  • http^1.1.0
  • flutter_testDesenvolvimento{"sdk":"flutter"}

README original

Texto original em inglês. Visite o GitHub para a versão atual.

Expandir / recolher README

Flutter Client SSE

Dart package to help consume Server Sent Events

Features:
  • Consumes server sent events
  • Returns parsed model of the event, id and the data

Getting Started

Import

Add the following import in the pubspec.yaml file

client_sse:
    git:
      url: https://github.com/pratikbaid3/flutter_client_sse
      path:
Example
///GET REQUEST
SSEClient.subscribeToSSE(
    method: SSERequestType.GET,
    url:
    'http://192.168.1.2:3000/api/activity-stream?historySnapshot=FIVE_MINUTE',
    header: {
        "Cookie":
        'jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2NDMyMTAyMzEsImV4cCI6MTY0MzgxNTAzMX0.U0aCAM2fKE1OVnGFbgAU_UVBvNwOMMquvPY8QaLD138; Path=/; Expires=Wed, 02 Feb 2022 15:17:11 GMT; HttpOnly; SameSite=Strict',
        "Accept": "text/event-stream",
        "Cache-Control": "no-cache",
    }).listen((event) {
        print('Id: ' + event.id!);
        print('Event: ' + event.event!);
        print('Data: ' + event.data!);
    },
);

///POST REQUEST
SSEClient.subscribeToSSE(
    method: SSERequestType.POST,
    url:
    'http://192.168.1.2:3000/api/activity-stream?historySnapshot=FIVE_MINUTE',
    header: {
        "Cookie":
        'jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2NDMyMTAyMzEsImV4cCI6MTY0MzgxNTAzMX0.U0aCAM2fKE1OVnGFbgAU_UVBvNwOMMquvPY8QaLD138; Path=/; Expires=Wed, 02 Feb 2022 15:17:11 GMT; HttpOnly; SameSite=Strict',
        "Accept": "text/event-stream",
        "Cache-Control": "no-cache",
    },
    body: {
        "name": "Hello",
        "customerInfo": {"age": 25, "height": 168}
    }).listen((event) {
            print('Id: ' + event.id!);
            print('Event: ' + event.event!);
            print('Data: ' + event.data!);
    },
);

Running Sample Backend

Nest The backend is in NestJS serving a single SSE api.

Installation

$ yarn install

Running the app

# development
$ yarn run start

# watch mode
$ yarn run start:dev