Migrating from Hurl
Hurl and apic are close cousins: one binary each, plain-text files,
captures and assertions. The move is mostly mechanical. A Hurl entry’s
sections become # @ directives above an .http request, and the files
become ones VS Code, JetBrains and Neovim can send with a click. One
thing changes for the better on the way: captures persist between runs,
so a single named request can run on its own with the token kept from an
earlier run.
How the concepts map
Section titled “How the concepts map”| Hurl | apic |
|---|---|
A .hurl file | a .http file; apic run file.http runs it top to bottom as a flow |
| An entry (request plus response section) | a ### block with # @name, so it can also run alone |
HTTP 200 | # @assert status == 200 |
[Captures] token: jsonpath "$.token" | # @capture token = body.$.token |
header "Location", cookie "sid" | header.location, cookie.sid |
jsonpath "$.items[0].id" | body.$.items[0].id (filters, slices and .. too; see body paths) |
status, duration, body | status, duration, body |
[Asserts] jsonpath "$.id" == 42 | # @assert body.$.id == 42 |
==, !=, >, >=, <, <= | the same |
contains, startsWith, endsWith, matches | the same names |
exists, not exists | the same |
isString, isInteger, isBoolean, isCollection, isEmpty | the same, with isArray or isObject for isCollection |
jsonpath "$.items" count == 3 | # @assert body.$.items length == 3 |
[Options] retry: 10 retry-interval: 2000 | # @retry 10 2s |
[Options] delay: 500 | # @sleep 500ms |
[Options] http2: true | GET https://… HTTP/2 on the request line |
[Options] insecure: true, cacert, cert, key | --insecure, or tls: in apic.yaml and --cacert, --cert, --key |
[BasicAuth] | # @auth basic user pass |
[FormParams], [MultipartFormData] | a urlencoded body, or a multipart body |
{{name}} with --variable name=value | {{name}} with --var name=value |
--variables-file vars.env | an environment in http-client.env.json, or .env |
HURL_name environment variables | APIC_VAR_name |
--test, --glob | apic run a.http b.http --keep-going |
--report-junit, --report-html, --report-json | apic test --format junit for features; apic run --report report.html; apic run --json |
--json (one line per file) | apic run --json (one object per request) |
A worked example
Section titled “A worked example”A Hurl file against the demo API:
POST http://localhost:8089/auth/login{"user": "alice", "password": "{{password}}"}HTTP 200[Captures]token: jsonpath "$.access_token"
GET http://localhost:8089/todos?done=falseAuthorization: Bearer {{token}}HTTP 200[Asserts]header "X-Total-Count" existsjsonpath "$" count >= 1jsonpath "$[0].done" == falsejsonpath "$[0].id" isStringThe same two requests in apic (with apic demo running in another
terminal). The host moves into the environment, each entry gets a name,
and each section line becomes a directive:
mkdir -p from-hurlcat > from-hurl/http-client.env.json <<'EOF'{ "local": { "baseUrl": "http://localhost:8089" }}EOFcat > from-hurl/todos.http <<'EOF'### Log in# @name login# @assert status == 200# @capture token = body.$.access_tokenPOST {{baseUrl}}/auth/loginContent-Type: application/json
{"user": "alice", "password": "{{password}}"}
### The open todos# @name open-todos# @assert status == 200# @assert header.x-total-count exists# @assert body.$ length >= 1# @assert body.$[0].done == false# @assert body.$[0].id isStringGET {{baseUrl}}/todos?done=falseAuthorization: Bearer {{token}}EOFapic run todos.http -C from-hurl --env local --var password=s3cret | tail -4✓ login 200 1 ms✓ open-todos 200 0 ms
2 passed · 2 requests · 1 msHurl adds Content-Type: application/json to a JSON body by itself; in a
.http file, write the header, since editors send exactly what the file
says. Then, because the token was captured into the session, the second
request runs on its own, with no login in the same run:
apic run open-todos -C from-hurl --env local | tail -1What does not carry over
Section titled “What does not carry over”- XPath,
sha256,md5and the filter chain (jsonpath "$.x" split "," nth 1). apic’s selectors are JSONPath, headers, cookies, status, duration and the raw body; a check that needs a transformation goes in a shell script aroundapic run --json. [Options]for curl internals such ascompressed,path-as-isorunix-socket. apic is not built on libcurl.--testreports per file. apic reports per request;--keep-goingand the summary line give the same pass/fail picture.- Hurl’s own format. apic reads
.httponly; the two formats are close enough that a search-and-replace does most of it.
Checklist
Section titled “Checklist”- One
.httpfile per.hurlfile, a###block and# @nameper entry -
HTTP <code>to# @assert status == <code> -
[Captures]to# @capture,[Asserts]to# @assert,jsonpath "$…"tobody.$… - Hosts to
{{baseUrl}}inhttp-client.env.json;--variables-fileto an environment -
[Options] retryto# @retry - A
Content-Typeheader on each JSON body -
apic validateis clean andapic fmt --checkpasses -
hurl --testin CI replaced withapic run *.http --keep-going
See also: the assertion operators,
# @retry and
apic compared with Hurl.
Hosted on Cloudflare, which keeps aggregate traffic statistics. No cookies, no tracking scripts, no per-request logs. Privacy