> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# FastAPI App with Multiple Endpoints

**Version/Environment (if relevant):** Domino Version 6.1 and Above

## **What:**

Domino's [Simple FastAPI example](https://support.domino.ai/support/s/article/Simple-FastAPI-example-as-a-Published-App-1718868040509) is a great way to get started with FastAPI in Domino, but what if you're ready to go a step further and set up a FastAPI app to take multiple GET and POST requests?

This guide assumes you've already installed FastAPI in your environment or set it up to install via *requirements.txt*.

## **How:**

## app.sh

Like many of our other App examples, this simply calls the Python script:

```
python app.py
```

## Python script

First, we need to import our packages and collect some environment variables:

```
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn
import os

runID = os.environ['DOMINO_RUN_ID']
userID = os.environ['DOMINO_PROJECT_OWNER']
projectID = os.environ['DOMINO_PROJECT_NAME']
```

Domino utilizes a reverse proxy, and App URLs have path prefixes that need to be included (e.g. `/username/app-name/app`). Therefore, we need to set a root\_path for our FastAPI app (see [https://fastapi.tiangolo.com/advanced/behind-a-proxy/#setting-the-root\_path-in-the-fastapi-app](https://fastapi.tiangolo.com/advanced/behind-a-proxy/#setting-the-root_path-in-the-fastapi-app)). With that example in mind, I was able to get to the swagger UI by modifying our code example as follows:

```
path_prefix = f"/{userID}/{projectID}/r/notebookSession/{runID}"

app = FastAPI(root_path=path_prefix)
```

We can then add routes as desired for our API:

```
class Item(BaseModel):
  name: str
  description: str
  price: float

@app.get("/")
async def root():
  return {"message": "Hello World"}

@app.get("/items/{item_id}")
async def read_item(item_id):
  return {"item_id": item_id}

@app.post("/items/")
async def create_item(item: Item):
  return item
```

Lastly, run the app:

```
if __name__ == "__main__":
  uvicorn.run("app:app",host="0.0.0.0",port=8888,reload = True)
```

Putting it all together, the complete app.py looks like:

```
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn
import os

runID = os.environ['DOMINO_RUN_ID']
userID = os.environ['DOMINO_PROJECT_OWNER']
projectID = os.environ['DOMINO_PROJECT_NAME']

path_prefix = f"/{userID}/{projectID}/r/notebookSession/{runID}"

print(f"App URL is https://<domino_url>/{path_prefix}")

app = FastAPI(root_path=path_prefix)

class Item(BaseModel):
  name: str
  description: str
  price: float

@app.get("/")
async def root():
  return {"message": "Hello World"}

@app.get("/items/{item_id}")
async def read_item(item_id):
  return {"item_id": item_id}

@app.post("/items/")
async def create_item(item: Item):
  return item

if __name__ == "__main__":
  uvicorn.run("app:app",host="0.0.0.0",port=8888,reload = True)
```

Similar to our Simple FastAPI example, hitting "View App" will bring up your FastAPI app with our "Hello World" message.

While our root page is accessible via the "official" app URL, you aren't able to append paths to this. For this, you need to use the session URL: `http://<your-domino-url>/<user>/<project>/r/notebookSession/<session_id>` (see [App URLS and URL parameters](https://support.domino.ai/support/s/article/App-URLs-and-URL-parameters-1718868036753)). To find this easily, you might add a print statement to your app.py, such as:

```
print(f"App URL is https://<domino_url>/{path_prefix}")
```

...which would print in your User Output when you start your App.

With that URL, you can utilize your other endpoints. For example:

`http://<your-domino-url>/<userID>/<projectID>/r/notebookSession/<runID>/item/foo`

You can also view the Swagger UI for your FastAPI app at:

`http://<your-domino-url>/<userID>/<projectID>/r/notebookSession/<runID>/docs`

**You're all set.**

## **Notes/Information:**

[https://support.domino.ai/support/s/global-search/fastAPI](https://support.domino.ai/support/s/global-search/fastAPI)

### **References/Internal Records:**


## Related topics

- [How-to guides](/knowledge-base/how-to-guides-overview.md)
- [Deploy agentic systems](/cloud/platform-capabilities/features/agents/deploy.md)
- [Architecture overview](/cloud/admin/architecture-and-deployment/architecture/index.md)
- [Performance tuning your Apps](/cloud/platform-capabilities/features/apps/app-logs-and-versioning/app-scalability-performance.md)
