b122de518c
File path = route. JSON/JSON5, dynamic .ts handlers + faker, templating, stateful CRUD (pagination/sort/persist), __variants, sequence, chaos, rate-limit, auth, validation, per-route + global proxy/record, splat routes, X-Scenario overlays, SSE. Visual docs (Scalar) at /__docs from a live OpenAPI 3 spec. OpenAPI import script. Zero-build via tsx. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
59 lines
3.4 KiB
Markdown
59 lines
3.4 KiB
Markdown
# __test — example routes
|
|
|
|
One example per feature. The `__` (double underscore) prefix is **served**; a
|
|
single `_` prefix (like `_lib.ts`) is ignored by the scanner.
|
|
|
|
| Route | File | Feature |
|
|
|---|---|---|
|
|
| `GET /__test/static` | `static.json` | plain JSON body |
|
|
| `POST /__test/created` → 201 | `created.post.201.json` | status + `__headers` + `__delay` + `__body` |
|
|
| `GET /__test/slow` | `slow.json` | `__delay: 1500` (fixed) |
|
|
| `GET /__test/jitter` | `jitter.json` | `__delay: [200, 1200]` (random per request) |
|
|
| `GET /__test/teapot` → 418 | `teapot.418.json` | status from filename |
|
|
| `GET /__test/profile` | `profile.json5` | JSON5 + `__variants` (try `?plan=pro`, header `X-Admin: 1`) |
|
|
| `GET/POST/… /__test/products[/:id]` | `products.crud.json` | stateful CRUD (6 routes) |
|
|
| `GET /__test/users/:id` | `users/[id].get.ts` | dynamic handler + faker + param (try `?verbose=1`) |
|
|
| `POST /__test/echo` | `echo.post.ts` | echo request |
|
|
| `GET /__test/quote` | `quote.get.ts` | handler importing a `_lib.ts` partial |
|
|
| `GET /__test/template` | `template.json` | `{{faker}}` / `{{query}}` / `{{headers}}` templating |
|
|
| `GET /__test/tpl/faker` | `tpl/faker.json` | many faker domains, nested |
|
|
| `GET /__test/tpl/user/:id` | `tpl/user/[id].json` | `{{params.id}}` + faker, no `.ts` needed |
|
|
| `GET /__test/tpl/echo` | `tpl/echo.json` | `{{query}}` + `{{headers}}`, unresolved stays literal |
|
|
| `GET /__test/tpl/typed` | `tpl/typed.json` | typed (number/bool) vs string interpolation |
|
|
| `GET /__test/tpl/list` | `tpl/list.json` | array — each element resolves independently |
|
|
| `GET /__test/flaky` | `flaky.json` | `__sequence` (202, 202, 200 …) |
|
|
| `GET /__test/roulette` | `roulette.json` | `__chaos` 50% → 503 |
|
|
| `GET /__test/limited` | `limited.json` | `__rateLimit` 3/10s → 429 |
|
|
| `GET /__test/secret` | `secret.json` | `__auth` Bearer `s3cret` → 401 |
|
|
| `POST /__test/signup` | `signup.post.json` | `__validate` → 422 |
|
|
| `GET /__test/proxied` | `proxied.json` | `__proxy` to a real upstream |
|
|
| `GET /__test/files/*` | `files/[...path].json` | splat route |
|
|
| `GET /__test/ticker` | `ticker.sse.json` | SSE stream |
|
|
| — | `_lib.ts` | shared data (ignored as a route) |
|
|
|
|
Scenario overlay: `routes/_scenarios/broken/__test/static.503.json` — try
|
|
`curl -H 'X-Scenario: broken' localhost:4100/__test/static` → 503.
|
|
|
|
Quick try:
|
|
|
|
```sh
|
|
curl localhost:4100/__test/static
|
|
curl -w '\n%{time_total}s\n' localhost:4100/__test/slow
|
|
curl "localhost:4100/__test/profile?plan=pro"
|
|
curl localhost:4100/__test/products
|
|
curl -X POST localhost:4100/__test/products -H 'content-type: application/json' -d '{"name":"New","price":1}'
|
|
curl "localhost:4100/__test/users/5?verbose=1"
|
|
curl localhost:4100/__test/quote
|
|
curl "localhost:4100/__test/template?q=hi"
|
|
for i in 1 2 3; do curl -s localhost:4100/__test/flaky; echo; done # sequence
|
|
curl -i localhost:4100/__test/secret # 401
|
|
curl -i -H 'authorization: Bearer s3cret' localhost:4100/__test/secret
|
|
curl -X POST localhost:4100/__test/signup -d '{"name":"x"}' -H 'content-type: application/json' # 422
|
|
curl "localhost:4100/__test/products?_sort=price&_order=desc&_limit=2"
|
|
curl localhost:4100/__test/files/a/b/c.txt # splat
|
|
curl -N localhost:4100/__test/ticker # SSE
|
|
curl -H 'X-Scenario: broken' localhost:4100/__test/static # scenario
|
|
```
|
|
|
|
All visible in the visual docs at `/__docs`.
|