Reflex Logo

Intro

Gallery

Hosting

Learn

Components

Recipes

API Reference

Onboarding
Hosting

Api-routes

/

Overview

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.

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.

Overriding this route will break the event communication

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

← Component StateOverview →

Did you find this useful?

HomeGalleryChangelogIntroductionHosting