Migrating from Bruno
Bruno and apic agree on the important thing: requests are plain files in git. Moving across is a translation of one text format into another, block by block. There is no importer yet, so this page is the mapping and a worked example; a collection of a few dozen requests takes an afternoon.
How the concepts map
Section titled “How the concepts map”| Bruno | apic |
|---|---|
Collection folder with bruno.json | a project: a directory with .http files and apic.yaml |
A .bru file (one request) | a ### block with # @name in a .http file; put a folder’s requests in one file |
meta { name, seq } | # @name; order in the file is the run order |
get { url }, post { url, body: json } | the request line: POST {{baseUrl}}/todos |
headers { … } | header lines under the request line |
body:json { … }, body:form-urlencoded, body:multipart-form | the body after a blank line; multipart for file parts |
auth:bearer, auth:basic, auth:awsv4, auth:digest, auth:oauth2 | # @auth bearer …, basic, aws, digest, oauth2; see authentication |
Collection-level auth in collection.bru | auth.default in apic.yaml |
environments/local.bru vars { … } | the local environment in http-client.env.json |
vars:secret [ … ] | http-client.private.env.json, kept out of git |
.env and {{process.env.NAME}} | .env in the project root, read as variables, or {{$dotenv NAME}} |
vars:pre-request { x: 1 } | a file variable @x = 1, or --var x=1 |
vars:post-response { token: res.body.access_token } | # @capture token = body.$.access_token, kept between runs |
assert { res.status: eq 200 } | # @assert status == 200 |
res.body.items: length 3, isString, isNumber, isEmpty, isNull | # @assert body.$.items length == 3, and the same predicates |
eq, neq, gt, gte, lt, lte | ==, !=, >, >=, <, <= |
contains, startsWith, endsWith, matches | the same names |
isDefined, isUndefined | exists, not exists |
notContains, notMatches, in, between, isTruthy, isJson | no direct form: assert the positive case, or two bounds for between |
bru run --env local | apic run <file>.http --env local |
bru run --csv-file-path rows.csv | apic run --data rows.csv |
--reporter-json, --reporter-junit, --reporter-html | apic run --json, apic test --format junit, apic run --report report.html |
| Script, tests and docs blocks | see what does not carry over |
A worked example
Section titled “A worked example”Two Bruno requests against the demo API, a log-in that keeps the token and a list that uses it:
meta { name: Log in seq: 1}
post { url: {{baseUrl}}/auth/login body: json}
body:json { {"user": "alice", "password": "{{password}}"}}
vars:post-response { token: res.body.access_token}
assert { res.status: eq 200}meta { name: Open todos seq: 2}
get { url: {{baseUrl}}/todos?done=false auth: bearer}
auth:bearer { token: {{token}}}
assert { res.status: eq 200 res.body: isArray res.body[0].done: eq false}and environments/local.bru:
vars { baseUrl: http://localhost:8089}vars:secret [ password]In apic, both requests go in one file, the environment in
http-client.env.json and the secret in the private file (with
apic demo running in another terminal):
mkdir -p from-brunocat > from-bruno/http-client.env.json <<'EOF'{ "local": { "baseUrl": "http://localhost:8089" }}EOFcat > from-bruno/http-client.private.env.json <<'EOF'{ "local": { "password": "s3cret" }}EOFprintf 'env: local\n' > from-bruno/apic.yamlcat > from-bruno/todos.http <<'EOF'### Log in# @name log-in# @assert status == 200# @capture token = body.$.access_tokenPOST {{baseUrl}}/auth/loginContent-Type: application/json
{"user": "alice", "password": "{{password}}"}
### Open todos# @name open-todos# @ref log-in# @auth bearer {{token}}# @assert status == 200# @assert body.$ isArray# @assert body.$[0].done == falseGET {{baseUrl}}/todos?done=falseEOFapic validate -C from-brunoapic run todos.http -C from-bruno | tail -4✓ 1 file, 2 requests, no problems✓ log-in 200 1 ms✓ open-todos 200 0 ms
2 passed · 2 requests · 1 ms# @ref log-in is the part Bruno has no word for: open-todos now logs
in by itself when there is no token, so apic run open-todos works on its
own, and the token survives to the next command.
What does not carry over
Section titled “What does not carry over”- Scripts and tests blocks.
script:pre-request,script:post-responseandtestsare JavaScript; apic has none, deliberately. Most of what they do is a# @capture, a# @assertor a--var; the rest belongs in a shell script aroundapic run --json. docsblocks. Use the### titleline (it becomes the request’s description inapic list) or#comments.- gRPC and WebSocket requests. apic is HTTP only.
- The Bruno app.
apic uiis a terminal UI; the VS Code extension sends.httpfiles with a click, as JetBrains and Neovim do.
Checklist
Section titled “Checklist”- One
.httpfile per Bruno folder, a###block per.brufile, inseqorder -
environments/*.brutohttp-client.env.json, secrets tohttp-client.private.env.json -
vars:post-responseto# @capture,assertto# @assert - Collection auth to
auth.defaultinapic.yaml -
# @refon requests that need a token - Every script and tests block rewritten or dropped on purpose
-
apic validateis clean andapic fmt --checkpasses -
bru runin CI replaced withapic run --jsonorapic test
See also: the .http format, the
assertion operators and
apic compared with Bruno.
Hosted on Cloudflare, which keeps aggregate traffic statistics. No cookies, no tracking scripts, no per-request logs. Privacy