Skip to main content
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

Step 1: Create the project

Create a new folder for your project if you don’t already have one.
mkdir basic-web-app
cd basic-web-app
vers init

Step 2: Launch the VM

vers run --vm-alias basic-web-app
Verify it’s running:
vers status
You should see your VM in a Running state.

Step 3: Connect and install dependencies

vers connect
Inside the VM:
# 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:
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

# 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:
{"message":"Hello from Vers","timestamp":"2026-03-31T..."}
{"message":"Hello, world!"}
Now exit the VM:
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
Port 8000 is one of the default routed ports. Make sure your server binds to :: (dual-stack) rather than 0.0.0.0 so Vers can route to it.

Step 7: Make a change

Connect back to the VM and add a new endpoint:
vers connect
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:
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