Getting started¶
This walks through installing apic, describing an API in .http files,
logging in once and reusing the token, wiring it into CI, and handing the
same files to an AI agent. It takes about ten minutes.
1. Install¶
go install github.com/dataGriff/api-caller/cmd/apic@latest # Go 1.25 or newer
curl -fsSL https://raw.githubusercontent.com/dataGriff/api-caller/main/install.sh | sh
APIC_VERSION=v1.2.3 pins a version, APIC_INSTALL_DIR=~/bin chooses
where it lands. The installer verifies the release checksum.
Each release has packages for Debian and Ubuntu, Fedora and RHEL, and Alpine, for amd64 and arm64, with the man pages and shell completions:
V=0.1.2 # the release, without the v
A=amd64 # or arm64
BASE=https://github.com/dataGriff/api-caller/releases/download/v$V
curl -fsSLO "$BASE/apic_${V}_linux_${A}.deb" && sudo dpkg -i "apic_${V}_linux_${A}.deb" # Debian, Ubuntu
curl -fsSLO "$BASE/apic_${V}_linux_${A}.rpm" && sudo rpm -i "apic_${V}_linux_${A}.rpm" # Fedora, RHEL
curl -fsSLO "$BASE/apic_${V}_linux_${A}.apk" && apk add --allow-untrusted "apic_${V}_linux_${A}.apk" # Alpine
There is no apt, yum or apk repository, so upgrading means installing
the next release's package. The packages are listed in checksums.txt
with the archives; verifying.md checks them the same way.
The apk is unsigned, hence --allow-untrusted: check its checksum first.
irm https://raw.githubusercontent.com/dataGriff/api-caller/main/install.ps1 | iex
It installs apic.exe into %LOCALAPPDATA%\Programs\apic, verifies
the release checksum, and adds the directory to your user PATH.
$env:APIC_VERSION = "v1.2.3" pins a version, $env:APIC_INSTALL_DIR
chooses the directory and $env:APIC_NO_MODIFY_PATH = "1" leaves PATH
alone. The zip is also on GitHub Releases
to install by hand.
docker run --rm -v "$PWD:/work" ghcr.io/datagriff/apic version
The image is the binary on scratch, about 7 MB, for amd64 and arm64.
The project directory is mounted at /work; see
the cookbook for CI systems that run
containers.
Check it with apic version.
2. See it work before writing anything¶
apic ui --demo
That serves a small fake API inside the same process and opens the terminal UI on an example project pointing at it. Press enter to send the request under the cursor, f to run a whole file as a flow, ? for every key, q to quit. Nothing is left behind.
The same example works from the plain CLI: apic demo writes it to
./apic-demo and serves the API, then in another terminal:
apic run login whoami -C apic-demo
apic run todos.http -C apic-demo --keep-going
apic run jobs.http -C apic-demo # submit a job and poll it to done
apic test -C apic-demo
Read apic-demo/auth.http, todos.http, jobs.http and explore.http
to see the files behind those commands. Between them they cover login and
API keys, a CRUD flow with filtering and a validation error, a job that
finishes after a couple of polls, a slow endpoint, a CSV download and a
GraphQL query, so every guide in these docs has something to run against.
3. Create a project¶
A project is any directory containing .http files. Keeping them in an
api/ folder next to your code works well. apic init writes a working
starting point:
apic init api --base-url https://dev.example.com --env dev
api/
apic.yaml
http-client.env.json
http-client.private.env.json
api.http
features/smoke.feature
.gitignore
apic.yaml sets defaults so you do not repeat flags:
env: dev
http-client.env.json holds per-environment values. $shared applies to
every environment.
{
"$shared": { "userId": 42 },
"dev": { "baseUrl": "https://dev.example.com", "user": "alice" },
"staging": { "baseUrl": "https://stg.example.com", "user": "alice" }
}
http-client.private.env.json has the same shape and holds secrets. apic
init gitignores it for you. apic masks values from this file wherever it
prints variables.
{
"dev": { "password": "s3cret" },
"staging": { "password": "other" }
}
If you already have an OpenAPI document, let apic write the first draft:
apic import openapi.yaml -o api
4. Write requests¶
api/auth.http:
### Log in and keep the token
# @name login
# @assert status == 200
# @capture token = body.$.access_token
POST {{baseUrl}}/auth/login
Content-Type: application/json
{"user": "{{user}}", "password": "{{password}}"}
api/users.http:
### Fetch a user
# @name get-user
# @description Fetch a single user by id
# @assert status == 200
# @assert body.$.id == {{userId}}
GET {{baseUrl}}/users/{{userId}}
Authorization: Bearer {{token}}
Accept: application/json
### Create a user
# @name create-user
# @assert status == 201
# @capture newUserId = body.$.id
POST {{baseUrl}}/users
Content-Type: application/json
{"name": "{{user}}", "email": "{{user}}@example.com"}
These are ordinary .http files. Open them in VS Code with the REST Client
extension, in a JetBrains IDE, or in Neovim with kulala, and the "Send
Request" action works as usual. apic's # @ lines are comments to those
tools.
Check the files parse, and see what you have:
cd api
apic validate
apic list
apic list user # only requests matching "user"
5. Run requests¶
apic run get-user
The first time, this fails with exit code 2 and tells you why:
error: users.http:6: missing variable
{{token}}: it is captured by request "login"; run `apic run login` first, or pass --var token=...
So log in (or add # @ref login to get-user and apic does this for you;
see dependencies):
apic run login
POST https://dev.example.com/auth/login
200 OK · 87 ms · 412 B
{ "access_token": "eyJ..." }
✓ status == 200
↳ token = eyJ...
The token is now in api/.apic/session.json for the dev environment (the
directory ignores itself from git). Every later run in dev can use
{{token}} until you clear it or log in again:
apic run get-user
apic run get-user --env staging # separate session, needs its own login
apic describe get-user # see where each variable comes from
apic session # what is captured
apic session clear # forget it
Or drive it interactively
apic ui shows the same project with the requests on the left and the
response, checks and session on the right, and marks which requests are
ready to run. See the terminal UI.
Override anything for one run:
apic run get-user --var userId=7
Run a whole file in order as a flow. It stops at the first failure and exits 1 if anything failed:
apic run users.http
apic run users.http --keep-going
6. Use the output in scripts¶
apic run get-user --body-only | jq .email
apic run users.http --json | jq -c '{name: .request.name, ok, status: .response.status}'
Exit codes make apic safe in set -e scripts and CI steps:
| Code | Meaning |
|---|---|
| 0 | ok |
| 1 | an assertion or capture failed |
| 2 | usage, parse error, unknown request or missing variable |
| 3 | network error or timeout |
7. Put it in CI¶
# .github/workflows/smoke.yml
- uses: dataGriff/api-caller/setup-apic@v0
- run: apic validate -C api --format github
- run: apic run auth.http users.http -C api --env staging --json --redact
env:
APIC_VAR_password: ${{ secrets.API_PASSWORD }}
The setup-apic action installs the latest release (or with: version:
v0.1.2 to pin one), verifies it against the published checksums, caches
it and puts it on PATH, on Linux, macOS and Windows runners. On any
other CI system, curl -fsSL
https://raw.githubusercontent.com/dataGriff/api-caller/main/install.sh | sh
does the same job, and where tools come as images there is
ghcr.io/datagriff/apic. --format github turns each validation problem into
an annotation on the pull request at the right line.
APIC_VAR_<name> environment variables override values from the env files,
so secrets never need to be in a file on the runner. --redact masks
header values, bodies, query values and captures in the stored log;
sensitive headers are masked even without it. apic run runs targets
in the order given, so auth.http users.http logs in first.
8. Add authentication¶
If the API needs more than a bearer token, put it in the file or the project config and apic handles it at send time:
# @auth aws service=execute-api region=eu-west-2
# @auth basic {{user}} {{password}}
# @auth oauth2 tokenUrl={{tokenUrl}} clientId={{clientId}} clientSecret={{clientSecret}}
AWS uses your existing credentials (environment, profiles, SSO via the AWS CLI); OAuth2 tokens are cached and refreshed. See auth.md.
9. Describe behaviour in Gherkin¶
Add phrases to requests and write features; apic runs them with no Cucumber runtime:
### Create a user
# @name create-user
# @step a user named {name} exists
POST {{baseUrl}}/users
...
### Fetch a user
# @name get-user
# @step I fetch the user
GET {{baseUrl}}/users/{{userId}}
Feature: Users
Scenario: Fetch a user by id
Given I run "login"
And a user named "alice" exists
When I fetch the user
Then the response status is 200
And the response body "$.name" is "alice"
apic test # features/ under the project
apic test --format junit --output report.xml
See testing.md for the full vocabulary.
10. Hand it to an agent¶
Add to your project's AGENTS.md or CLAUDE.md:
API requests live in api/*.http and are run with apic from the api/ directory:
`apic list --json`, `apic describe <id> --json`, `apic run <id> --json`.
Run `apic run login` once before requests that need {{token}}.
Or register the MCP server so the agent calls requests as tools:
claude mcp add api -- apic mcp --dir ./api --env dev
See agents.md for the details.
Next¶
- cheatsheet.md: every directive, selector and operator on one page
- cookbook.md: worked recipes for CI, AWS, OAuth2, uploads and polling
- format.md: everything the
.httpdialect supports - cli.md: every command and flag
- tui.md: the terminal UI
- faq.md: short answers when something misbehaves