-
If I'm going to use idom as the UI for a web app where FastAPI is the backend, is it possible to execute a fetch request to grab data from an endpoint on the fastapi side? I can see in the docs / examples where static files are served us such as images or href, but I don't see anything about data. The example I can think of is a paginated table where the next button grabs the data to load for the next page of results. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
All the code you write with IDOM is server-side. You have access to all the same data that your normal FastAPI routes would so there's no need to request data from a route. You might write this in the following way: from idom import component, use_effect, use_state
@component
def MyTable():
table_rows, set_table_rows = use_state([])
@use_effect
def get_table_rows_from_database():
rows_from_database = get_rows_from_database(...)
set_table_rows(rows_from_database)
if not table_rows:
return LoadingTableSpinner()
else:
return html.table(...) # make a table out of `table_rows` If your @component
def MyTable():
...
@use_effect
async def get_table_rows_from_database():
...
... Unfortunately there's not a lot of documentation on |
Beta Was this translation helpful? Give feedback.
All the code you write with IDOM is server-side. You have access to all the same data that your normal FastAPI routes would so there's no need to request data from a route. You might write this in the following way:
If your
get_rows_from_database
function happens to beasync
th…