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

# Basic web app

> Deploy a Python FastAPI app on a Vers VM

Deploy a simple API backend on a Vers VM using Python and FastAPI. You'll create a VM, install dependencies, write an app, and see it respond to requests — all in a few minutes.

## Prerequisites

* Vers CLI [installed and authenticated](/installation)

## Step 1: Create the project

Create a new folder for your project if you don't already have one.

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
mkdir basic-web-app
cd basic-web-app
vers init
```

## Step 2: Launch the VM

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers run --vm-alias basic-web-app
```

Verify it's running:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers status
```

You should see your VM in a `Running` state.

## Step 3: Connect and install dependencies

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers connect
```

Inside the VM:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# Set up DNS for outbound internet access
echo 'nameserver 8.8.8.8' > /etc/resolv.conf

# Install Python and pip
apt-get update && apt-get install -y python3 python3-pip

# Install FastAPI and uvicorn
pip3 install fastapi uvicorn
```

## Step 4: Write the app

Still inside the VM, create a simple API:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
mkdir -p /app
cat > /app/main.py << 'EOF'
from fastapi import FastAPI
from datetime import datetime

app = FastAPI()

@app.get("/")
def root():
    return {
        "message": "Hello from Vers",
        "timestamp": datetime.now().isoformat()
    }

@app.get("/health")
def health():
    return {"status": "ok"}

@app.get("/greet/{name}")
def greet(name: str):
    return {"message": f"Hello, {name}!"}
EOF
```

## Step 5: Start the server and verify

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# Start uvicorn on port 8000, binding to all interfaces
cd /app
uvicorn main:app --host '::' --port 8000 &

# Give it a second to start
sleep 1

# Test the endpoints
curl -s http://localhost:8000
curl -s http://localhost:8000/greet/world
```

You should see JSON responses:

```json theme={"theme":{"light":"min-light","dark":"min-dark"}}
{"message":"Hello from Vers","timestamp":"2026-03-31T..."}
{"message":"Hello, world!"}
```

Now exit the VM:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
exit
```

## Step 6: View it in your browser

Your API is live at:

```
https://<vm-id>.vm.vers.sh:8000
```

Replace `<vm-id>` with your VM's ID (shown in `vers status`). Vers terminates TLS at the proxy, so your VM serves plain HTTP but browsers see HTTPS — no cert setup needed.

FastAPI also gives you interactive API docs for free:

```
https://<vm-id>.vm.vers.sh:8000/docs
```

<Info>
  Port 8000 is one of the [default routed ports](/vm-access#available-ports). Make sure your server binds to `::` (dual-stack) rather than `0.0.0.0` so Vers can route to it.
</Info>

## Step 7: Make a change

Connect back to the VM and add a new endpoint:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers connect
```

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
cat >> /app/main.py << 'EOF'

@app.get("/items")
def items():
    return [
        {"id": 1, "name": "Laptop", "price": 999.99},
        {"id": 2, "name": "Mouse", "price": 29.99},
        {"id": 3, "name": "Keyboard", "price": 79.99},
    ]
EOF

# Restart the server to pick up changes
pkill uvicorn
cd /app && uvicorn main:app --host '::' --port 8000 &
sleep 1

# Test the new endpoint
curl -s http://localhost:8000/items
```

Refresh the `/docs` page in your browser — the new endpoint appears automatically. Exit when done:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
exit
```

## What you learned

* Creating a Vers VM and connecting via SSH
* Installing Python packages and running a FastAPI server
* Serving an API accessible over HTTPS
* Using FastAPI's auto-generated docs on a Vers VM
* Making live changes to a running app

## Next steps

* [Coding agent (SSH)](/examples/coding-agent-ssh) — let an AI agent build your app on a Vers VM
* [Accessing your instance](/vm-access) — networking, ports, and SSH details
