local client (dart with eventsource) / server (python with flask-sse) implementation to send bidirectional server-sent-event from server to client.
cd server/flask
python3 run.py
cd client/mysse-dart
dart run
server will send this payload as an sse event through the client
#!/bin/bash
curl -X GET \
-H "Content-Type: application/json" \
-d '{"foo": "bar"}' \
http://127.0.0.1:5001/hello
url = "http://127.0.0.1:5001/hello"
data = {"key": "value"}
r = requests.post(url, json=data)
print("status_code: {}".format(r.status_code)
print("response-text: {}".format(r.json()))
# get jwt token
url = "http://127.0.0.1:5001/rest/login"
data = {"username": "kivanc", "password": "1234"}
r = requests.post(url, json=data)
output = r.json()
token = output['access_token']
# now send through auth_hello
url = "http://127.0.0.1:5001/auth_hello"
data = {"key": "value"}
headers = {'Authorization': 'Bearer {}'.format(token)}
r = requests.post(url, json=data, headers=headers)
print("status_code: {}".format(r.status_code)
print("response-text: {}".format(r.json()))
install redis server
sudo apt-get install redis-server
install flask and flask-sse
sudo apt-get install python3-flask
sudo pip3 install flask-sse
install dart
https://dart.dev/get-dart
install dependencies
cd mysse
dart pub get
https://pypi.org/project/Flask-SSE/
https://github.com/featurehub-io/featurehub/tree/main/sdks/dart/dart-eventsource
https://maxhalford.github.io/blog/flask-sse-no-deps/