# List Every API Endpoint in an Express App

An agent maps all 20 endpoints of an Express app from its mounted routers, then flags which of the 11 writes check who owns the record they change.

[Run this on Rush](https://cloud.getrush.ai/run/api-endpoint-inventory/express/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent starts at `src/main.ts`, which mounts the router from `src/app/routes/routes.ts` under `/api`, then reads `auth/auth.ts` and every controller and service under `src/app/routes/`. The `@route` comments and the README disagree with the code in places (`/article/:slug`, the `/api/tags` prefix), so it documents the code.

To check its reading, it builds the app with `npm run build` and walks the built router's stack with a small script outside the clone, which prints 19 routes under `/api`. It then starts `dist/api/main.js` with no database and calls each required-auth route without a token. The repository is left untouched; the report is written to the session's artifacts.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Write endpoints.md for this Express app: every method and path, following app.use and Router mounts in order, with the handler file:line, its auth middleware (required, optional or none), parameters and validation, and any ownership check. Install with the repository's package manager, run its build and tests, and confirm the route list against the built router. Report the endpoint count and which writes have no ownership check. Do not edit the repository. If a pull request follows this prompt, check out its head first and name the commit you inventoried.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on gothinkster/node-express-realworld-example-app at 30b68e1: a 66-line `endpoints.md` with 20 endpoints (19 under `/api` plus `GET /`), no code change. Of 11 writes, 3 check ownership (`PUT` and `DELETE /articles/:slug`, `DELETE /articles/:slug/comments/:id`). The other 8 act only on the caller's own user id, so no write lets one user change another's data. `npm run build` passed with `Successfully ran target build for project api`, and every required-auth route answered `401` without a token.

The baseline `npm test` already failed: `Tests: 7 failed, 1 todo, 19 passed, 27 total`, all in `auth.service.test.ts` with `Environment variable not found: DATABASE_URL`. A reviewer decides whether to fix that suite's Prisma mock. Postgres never ran, so the 403, 404 and 500 paths are from reading code, not requests.

## Run it on every pull request labelled api

An automation with a `github` trigger on `pull_request.labeled` and the label `api` runs this prompt with the pull request added after it. Diffing its `endpoints.md` with main's shows a route that moved from `auth.required` to optional, which adds no new path and so slips past a route count.

## Why run it on Rush?

The run separated two meanings of "no ownership check": a write that touches someone else's record unguarded, and one that only ever writes the caller's own row, like follow and favorite. It also found that `DELETE /articles/:slug/comments/:id` ignores the slug, and that by the code, unknown slugs on favorite return 500 instead of a 4xx.

## Frequently asked questions

### How was the route count confirmed?

By loading the built `routes.js` and walking Express's router stack, which printed 19 method and path pairs under `/api`. `GET /` lives in `src/main.ts` outside that router, which makes 20.

### Why did the probe stop at 401s?

There was no Postgres in the run. Without a database the app still rejects a missing token, but `GET /api/tags` returned 500, so anything past authentication is marked as read from code.

## More Express jobs

- [Compare Express 5 and Hono for an Express Project](https://getrush.ai/run/compare-libraries/express/)
- [Convert an Express App from JavaScript to TypeScript](https://getrush.ai/run/convert-javascript-to-typescript/express/)
- [Fix an Express API Bug From a Datadog Monitor Alert](https://getrush.ai/run/fix-datadog-alerts/express/)

## The same job on other stacks

- [List Every API Endpoint in a FastAPI App](https://getrush.ai/run/api-endpoint-inventory/fastapi/)
- [Inventory the API Endpoints of a Gin Service](https://getrush.ai/run/api-endpoint-inventory/gin/)
- [Inventory the API Endpoints of a Go Service](https://getrush.ai/run/api-endpoint-inventory/go/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
