# API — URL Shortener (FastAPI)

A deliberately tiny FastAPI app. Three routes only:

| Method | Path | Body / Param | Returns |
|---|---|---|---|
| `GET` | `/health` | — | `{"status": "ok"}` |
| `POST` | `/shorten` | `{"url": "https://..."}` | `{"code": "abc123", "short_url": "..."}` |
| `GET` | `/{code}` | path param | `302` redirect to the original URL |

## Storage

Plan A uses an **in-process dict** (`URLS`). Lesson 03 swaps it for
Postgres via the docker-compose stack. Lesson 07 swaps that for a
managed RDS / Cloud SQL instance.

The dict means the API loses state on restart — that's fine for Plan A;
the **container lifecycle is the lesson**, not the persistence.

## Configuration

| Env var | Default | Purpose |
|---|---|---|
| `BASE_URL` | `http://localhost:8000` | Used to build the `short_url` in `POST /shorten` responses. |
| `LOG_LEVEL` | `info` | Passed to uvicorn. |

Add new env vars to **both this README and the `.env.example`** that
Lesson 03 introduces.

## Local run

```bash
pip install -r requirements.txt
uvicorn app:app --reload --port 8000

# Try it:
curl -s localhost:8000/health
curl -s -X POST localhost:8000/shorten -H 'content-type: application/json' \
  -d '{"url": "https://anthropic.com"}'
```
