Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vlcinsky/fastapi-sse-htmx
https://github.com/vlcinsky/fastapi-sse-htmx
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/vlcinsky/fastapi-sse-htmx
- Owner: vlcinsky
- Created: 2021-06-05T22:32:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-06-05T22:40:23.000Z (over 3 years ago)
- Last Synced: 2024-10-14T09:26:01.426Z (2 months ago)
- Language: Python
- Size: 26.4 KB
- Stars: 37
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
- awesome-htmx - htmx and SSE with FastAPI - FastAPI based web app sending Server Sent Events to frontend app created with htmx. (Examples by Back-end / Python-based (Django, FastAPI, Flask))
README
=========================
htmx and SSE with FastAPI
=========================
This is experiment testing FastAPI based web app sending Server Sent Events to frontend app created with htmx.Installation
============
Using python 3.9 and having poetry installed::$ poetry install
Configuration
=============
There is nothing to configure.Usage
=====
Activate virtual environment::$ poetry shell
(.venv)$Start the web app::
(.venv)$ uvicorn app:app
Open http://localhost:8000 in a browser.
You shall see simple page with a table, where two cells are updating it's content according to events generated by the server.
.. image:: img/page.png
Red rectangles show text, which is dynamically updated.
To test the events from command line::
$ curl -N http://localhost:8000/status_updates
event: #of_subscribers
data: 0
retry: 30000event: #of_subscribers
data: 1
retry: 30000event: #of_subscribers
data: 2
retry: 30000event: #of_subscribers
data: 3
retry: 30000event: #of_news
data: 4
retry: 30000event: #of_news
data: 5
retry: 30000