Crates.io | nu_plugin_from_sse |
lib.rs | nu_plugin_from_sse |
version | 0.4.0 |
source | src |
created_at | 2024-03-06 15:00:41.810434 |
updated_at | 2024-07-02 16:25:26.493735 |
description | Nushell plugin to convert a HTTP server sent event stream to structured data |
homepage | |
repository | https://github.com/cablehead/nu_plugin_from_sse |
max_upload_size | |
id | 1164890 |
size | 175,550 |
nu
streaming plugin: nu_plugin_from_sse
This plugin was forked from the nu_plugin_example.
From within nushell:
cargo install --locked nu_plugin_from_sse
plugin use ~/.cargo/bin/nu_plugin_from_sse
# and then restart nu or use plugin add to activate
nu_plugin_from_sse
provides one command:
from sse
This command transforms HTTP SSE (Server-Sent Events) into structured records with the shape:
{
id: string, // Unique identifier for the SSE event
event: string, // Type of event
data: string // Data payload of the event
}
If your SSE endpoint dispatches initial events upon connection, then pauses—awaiting rare updates—you won't see any output until the first new update after connecting. This behavior is due to nu's table buffering mechanism, where a duration timeout is factored in only during active input processing.
An easy workaround for this issue is to pipe to
each
.
Copy this text to your clipboard:
event: creatureAlert
id: 1
data: {"id":"uni123","type":"Unicorn","lat":45.4235,"lon":-75.6979,"urgency":"high","desc":"Injured near Crystal River."}
Use bp
to pipe it:
bp | from sse | update data { from json }
http get https://ndyg.cross.stream/projects/enchanted-animal-rescue/rescue-feed |
from sse |
update data { from json }