✨ Announcing our seed funding led by Lux Capital! Read more about it on our blog

Search documentation...




[ Learn ]

[ Concepts ]

[ Reference ]

Backend API Routes

In addition to your frontend app, Reflex also uses a FastAPI backend to serve your app.
To add additional endpoints to the backend API, you can use app.add_api_route and add a route that returns JSON.
async def api_test(item_id: int):
    return {"my_result": item_id}

app = rx.App()
app.api.add_api_route("/items/{item_id}", api_test)
Now you can access the endpoint at localhost:8000/items/23 and get the result.
This is useful for creating a backend API that can be used for purposes other than your Reflex app.

Reserved Routes

Some routes on the backend are reserved for the runtime of Reflex, and should not be overriden unless you know what you are doing


localhost:8000/ping/: You can use this route to check the health of the backend.
The expected return is "pong"


localhost:8000/_event: the frontend will use this route to notify the backend that an event occurred


localhost:8000/_upload: This route is used for the upload of file when using rx.upload()
← Wrapping ReactUse Middleware →

Copyright © 2023 Pynecone, Inc.