v2.0.3
flutter_client_sse
Dart 包,用于帮助消费 SSE API。它通过返回事件、ID 和数据的解析模型来消费服务器发送事件。
110喜欢 4.5万近 30 天下载150Pub 分数
AndroidiOSWebmacOSWindowsLinux
用于消费SSE API的Dart包。通过返回事件、id和数据的解析模型来消费服务器发送事件
以下为英文项目原文快照,最新内容请访问 GitHub。
Dart package to help consume Server Sent Events
Add the following import in the pubspec.yaml file
client_sse:
git:
url: https://github.com/pratikbaid3/flutter_client_sse
path:
///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!);
},
);
Nest The backend is in NestJS serving a single SSE api.
$ yarn install
# development
$ yarn run start
# watch mode
$ yarn run start:dev
依赖清单 3 项
{"sdk":"flutter"}^1.1.0{"sdk":"flutter"}先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗