# HTTP API

> The serve feature — browser UI, REST endpoints under /api/v1, CORS, and access logging.

---

LLMS index: [llms.txt](/codeweb/llms.txt)

---

## Start the server {#start-the-server}

Built with the `serve` feature, `codeweb serve` loads the project store and starts an HTTP server with an embedded browser UI:

```bash
cargo build --release --features serve
codeweb serve --addr 127.0.0.1:3000 --open
```

| Flag | Default | Meaning |
| ---- | ------- | ------- |
| `-p, --project` | `.` | Project directory |
| `-a, --addr` | `127.0.0.1:3000` | Bind address (host:port) |
| `--open` | off | Open the browser after startup |
| `--log-level` | `info` | Access log level: `info` or `debug` |

The UI offers a node list with search, a Cytoscape.js graph canvas with dagre layout, and a detail panel with callers/callees. Requests are CORS-permissive and logged to `.codeweb/` in the project directory.

## REST endpoints {#rest-endpoints}

All endpoints live under `/api/v1` and return JSON unless noted.

| Method | Path | Parameters | Description |
| ------ | ---- | ---------- | ----------- |
| GET | `/api/v1/stats` | — | Node counts by type, edge count, project name |
| GET | `/api/v1/files` | — | Analyzed files with node counts |
| GET | `/api/v1/nodes` | `search`, `node_type`, `orphan`, `low_degree`, `limit` (default 100), `offset` (default 0) | Filter and paginate node summaries; `search` sorts by match rank |
| GET | `/api/v1/nodes/:id` | — | Node properties, direct callers, callees |
| GET | `/api/v1/nodes/:id/callers` | `limit`, `offset`, `depth` | Upstream neighbors |
| GET | `/api/v1/nodes/:id/callees` | `limit`, `offset`, `depth` | Downstream neighbors |
| GET | `/api/v1/nodes/search-sql` | `q` (required) | Search `mapper`/`sql` nodes by SQL content, scored |
| GET | `/api/v1/trace` | `from` (required), `depth` (default 2, capped at 10), `max_nodes` (default 500) | Bidirectional call chain trees; response reports `truncated` |
| GET | `/api/v1/columns` | exactly one of `procedure`, `package`; optional `table` | Aggregated column analysis (issue #165 JSON) |
| GET | `/api/v1/lineage` | `target` (required), `direction` (`upstream`/`downstream`/`both`), `depth` (default 5) | Table/column lineage |
| POST | `/api/v1/query` | body: [QuerySpec JSON](/codeweb/docs/trace-and-query/#declarative-queries) | Declarative traversal |
| GET | `/api/v1/export` | `format`: `dot`, `json`, `ndjson`, `mermaid` | Download the graph |
| GET | `/api/v1/graph` | — | Full graph payload used by the browser UI canvas |

Status codes follow the convention: `404` when a name matches nothing, `400` for ambiguous names or invalid parameters (for example passing both `procedure` and `package` to `/api/v1/columns`).

## Examples {#examples}

```bash
codeweb serve -p my-project --addr 127.0.0.1:3000 &

curl -s http://127.0.0.1:3000/api/v1/stats
curl -s "http://127.0.0.1:3000/api/v1/nodes?search=order&node_type=proc&limit=10"
curl -s "http://127.0.0.1:3000/api/v1/trace?from=process_order&depth=3"
curl -s "http://127.0.0.1:3000/api/v1/lineage?target=orders&direction=upstream"
curl -s "http://127.0.0.1:3000/api/v1/nodes/search-sql?q=UPDATE%20inventory"
curl -s -X POST http://127.0.0.1:3000/api/v1/query \
  -H 'Content-Type: application/json' \
  -d '{"start":{"type":"proc","name":"order"},"collect":"paths"}'
curl -s "http://127.0.0.1:3000/api/v1/export?format=ndjson" -o graph.ndjson
```

## Security boundaries {#security-boundaries}

The server reads the project store and binds the address you give it. It does not authenticate requests, and CORS is fully permissive, so treat it as a local development tool: do not expose it to untrusted networks. Read paths may point anywhere under `analysis.paths`; the serve mode has no write endpoints.

---

Backlinks:

- [CLI reference](/codeweb/docs/cli-reference/)
- [Getting started](/codeweb/docs/getting-started/)
