|
| 1 | +# yapi — LLM Skill Guide |
| 2 | + |
| 3 | +yapi is a CLI-first, git-friendly API client. You define requests in YAML files and run them from the terminal. No GUI, no accounts, no state — just files and a binary. |
| 4 | + |
| 5 | +## When to Use yapi |
| 6 | + |
| 7 | +- Send HTTP, gRPC, GraphQL, or TCP requests |
| 8 | +- Chain multiple requests together (auth flow, then use the token) |
| 9 | +- Assert on responses (status codes, body content via JQ) |
| 10 | +- Run API test suites with `yapi test` |
| 11 | +- Poll endpoints until a condition is met |
| 12 | + |
| 13 | +## Core Concepts |
| 14 | + |
| 15 | +**Every request file starts with `yapi: v1`.** This is required. |
| 16 | + |
| 17 | +**File extension:** `.yapi.yml` (or `.yapi.yaml`). Test files use `.test.yapi.yml`. |
| 18 | + |
| 19 | +**Project config:** `yapi.config.yml` at the project root defines environments and base URLs. yapi walks up the directory tree to find it. |
| 20 | + |
| 21 | +**Variables:** Use `${VAR}` syntax. Resolved from: chain step outputs > environment vars > shell env > defaults. Default values: `${VAR:-fallback}`. |
| 22 | + |
| 23 | +## Quick Reference |
| 24 | + |
| 25 | +### Run a request file |
| 26 | + |
| 27 | +```bash |
| 28 | +yapi run request.yapi.yml |
| 29 | +yapi run request.yapi.yml -e prod # with environment |
| 30 | +``` |
| 31 | + |
| 32 | +### Quick one-off request (no file needed) |
| 33 | + |
| 34 | +```bash |
| 35 | +yapi send https://api.example.com/users # GET |
| 36 | +yapi send https://api.example.com/users '{"name":"Alice"}' # POST (auto-detected) |
| 37 | +yapi send -X PUT https://api.example.com/users/1 '{"name":"Bob"}' -H 'Authorization: Bearer tok' |
| 38 | +yapi send https://api.example.com/users --jq '.[0].name' |
| 39 | +``` |
| 40 | + |
| 41 | +### Minimal request file |
| 42 | + |
| 43 | +```yaml |
| 44 | +yapi: v1 |
| 45 | +url: https://api.example.com/users |
| 46 | +method: GET |
| 47 | +``` |
| 48 | +
|
| 49 | +### POST with body |
| 50 | +
|
| 51 | +```yaml |
| 52 | +yapi: v1 |
| 53 | +url: https://api.example.com/users |
| 54 | +method: POST |
| 55 | +body: |
| 56 | + name: Alice |
| 57 | + role: admin |
| 58 | +``` |
| 59 | +
|
| 60 | +### Chain requests (pass data between steps) |
| 61 | +
|
| 62 | +```yaml |
| 63 | +yapi: v1 |
| 64 | +chain: |
| 65 | + - name: login |
| 66 | + url: https://api.example.com/auth |
| 67 | + method: POST |
| 68 | + body: |
| 69 | + username: ${USERNAME} |
| 70 | + password: ${PASSWORD} |
| 71 | + expect: |
| 72 | + status: 200 |
| 73 | + |
| 74 | + - name: get_profile |
| 75 | + url: https://api.example.com/me |
| 76 | + method: GET |
| 77 | + headers: |
| 78 | + Authorization: Bearer ${login.token} |
| 79 | + expect: |
| 80 | + status: 200 |
| 81 | + assert: |
| 82 | + - .email != null |
| 83 | +``` |
| 84 | +
|
| 85 | +### Assert on responses |
| 86 | +
|
| 87 | +```yaml |
| 88 | +expect: |
| 89 | + status: 200 |
| 90 | + assert: |
| 91 | + - . | length > 0 # JQ expression, must evaluate to true |
| 92 | + - .[0].id != null |
| 93 | + - .count >= 10 |
| 94 | +``` |
| 95 | +
|
| 96 | +### Run tests |
| 97 | +
|
| 98 | +```bash |
| 99 | +yapi test ./tests # run all *.test.yapi.yml files |
| 100 | +yapi test ./tests -e staging # against a specific environment |
| 101 | +yapi test ./tests -p 8 # parallel execution |
| 102 | +``` |
| 103 | + |
| 104 | +### Environments |
| 105 | + |
| 106 | +Define in `yapi.config.yml`: |
| 107 | + |
| 108 | +```yaml |
| 109 | +yapi: v1 |
| 110 | +default_environment: local |
| 111 | +environments: |
| 112 | + local: |
| 113 | + url: http://localhost:3000 |
| 114 | + vars: |
| 115 | + API_KEY: dev_key |
| 116 | + prod: |
| 117 | + url: https://api.example.com |
| 118 | + vars: |
| 119 | + API_KEY: ${PROD_API_KEY} |
| 120 | +``` |
| 121 | +
|
| 122 | +Then in request files, use `${url}` and `${API_KEY}` — they resolve from the active environment. |
| 123 | + |
| 124 | +## Documentation Map |
| 125 | + |
| 126 | +The docs are split into **topics** (concepts/features) and **commands** (CLI reference). Read only what you need. |
| 127 | + |
| 128 | +### Topics (`docs/topics/`) |
| 129 | + |
| 130 | +| File | Read this when you need to... | |
| 131 | +|------|-------------------------------| |
| 132 | +| `config.md` | Know all available YAML fields (full schema reference) | |
| 133 | +| `chain.md` | Chain multiple requests, pass data between steps | |
| 134 | +| `assert.md` | Write assertions on status, body, or headers | |
| 135 | +| `variables.md` | Understand `${VAR}` interpolation and resolution order | |
| 136 | +| `environments.md` | Set up dev/staging/prod environments | |
| 137 | +| `jq.md` | Filter or transform response bodies with JQ | |
| 138 | +| `testing.md` | Use the built-in test runner (`yapi test`) | |
| 139 | +| `polling.md` | Poll an endpoint until a condition is met (`wait_for`) | |
| 140 | +| `send.md` | Use `yapi send` for quick curl-like requests | |
| 141 | +| `protocols.md` | Use gRPC, GraphQL, or TCP (not just HTTP) | |
| 142 | + |
| 143 | +### Commands (`docs/commands/`) |
| 144 | + |
| 145 | +Each file documents one CLI command: `yapi_run.md`, `yapi_send.md`, `yapi_test.md`, `yapi_stress.md`, `yapi_watch.md`, etc. Refer to these for flag details and usage examples. |
| 146 | + |
| 147 | +## Common Patterns |
| 148 | + |
| 149 | +**Auth flow then use token:** |
| 150 | +Chain with `${login.token}` in the Authorization header of subsequent steps. |
| 151 | + |
| 152 | +**Validate an API contract:** |
| 153 | +Use `expect.assert` with JQ expressions. Chain variable assertions let you compare across steps: `.id == ${create.id}`. |
| 154 | + |
| 155 | +**Wait for async job:** |
| 156 | +Use `wait_for.until` with a `period` or `backoff` and `timeout`. |
| 157 | + |
| 158 | +**Filter noisy responses:** |
| 159 | +Use `jq_filter` in the YAML or `--jq` on the CLI. |
| 160 | + |
| 161 | +## Gotchas |
| 162 | + |
| 163 | +- `yapi: v1` at the top of every file — missing it is the most common error |
| 164 | +- Variables are `${VAR}`, not `$VAR` |
| 165 | +- Assertions are JQ expressions that must evaluate to `true` |
| 166 | +- Chains stop on first failure (fail-fast) |
| 167 | +- Protocol is auto-detected from URL scheme: `grpc://`, `tcp://`, or HTTP by default |
0 commit comments