Support custom HTTP requests
See original GitHub issueSee: https://discuss.streamlit.io/t/streamlit-restful-app/409
Some users would like to have their Streamlit servers work double duty as both a Streamlit app server and a data server (for REST endpoints, for example)
API proposal 1
A traditional-looking API for that would be something like:
st.server.add_route('foo', foo_callback)
Then, when a POST or GET HTTP request is made against /foo
, the callback foo_callback
would handle it and return a response.
I haven’t thought through whether this would be possible to implement given our current “run from the top” architecture. It’s possible this would require a big refactor.
API proposal 2
A more Streamlit-style API would be something like:
if st.server.request.foo == 'bar':
st.server.respond({'data': df})
# And .respond() would cause the script to finish executing immediately.
In this proposal, the if
condition would be true if:
- The user sent a POST to
/
withfoo
set tobar
(either in a form or in JSON) - Or the user sent a GET to
/?foo=bar
This API is easier to implement and arguably easier to understand.
My preference at this point is proposal 2.
That said, both of these proposals are just straw-man designs to start a discussion. I believe neither of these is ready to implement at this point.
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:84
- Comments:25 (1 by maintainers)
Top GitHub Comments
Any progress on this?
As a temporary workaround, piggybacking on FastAPI may be a solution to support HTTP and have OpenAPI docs as suggested in https://github.com/streamlit/streamlit/issues/439#issuecomment-635796911. I understand that this adds complexity as it needs two services (streamlit and FastAPI server) to be running in parallel, but I am sharing it here anyway as it may be interesting for some to explore for the time being!
https://davidefiocco.github.io/streamlit-fastapi-ml-serving (video) https://github.com/davidefiocco/streamlit-fastapi-model-serving/