This guide helps you set up and use the a7 CLI to manage your API7 Enterprise Edition (API7 EE) instance.
Before installing a7, ensure you have:
- Go 1.22 or higher.
- An API7 Enterprise Edition instance with the Admin API enabled. The default Admin API port is 7443 (HTTPS).
Install the a7 CLI directly with the Go command:
go install github.com/api7/a7/cmd/a7@latestAlternatively, you can build from source:
git clone https://github.com/api7/a7.git
cd a7
make buildThe resulting binary will be located in the current directory.
The a7 CLI uses "contexts" to manage different API7 EE environments. A context stores the server address, the token, and the target gateway group. Use the context create command to set up your first connection.
a7 context create local \
--server https://localhost:7443 \
--token your-api7-token \
--gateway-group default \
--tls-skip-verifyExample output:
✓ Context "local" created and saved.
✓ Context "local" set as current context.Your configuration is stored in ~/.config/a7/config.yaml by default. You can override this location by setting the A7_CONFIG_DIR environment variable.
If you prefer not to use a context, you can set the following environment variables:
A7_SERVER: The Admin API server address (e.g.,https://localhost:7443).A7_TOKEN: Your API7 EE token.A7_GATEWAY_GROUP: The target gateway group name.
Check if a7 can communicate with your API7 EE instance by listing the available gateway groups:
a7 gateway-group listIf the connection is successful, you will see a list of gateway groups.
Once you have a working context, you can start managing routes within a gateway group.
Create a file named route.json with the following content:
{
"id": "getting-started",
"name": "getting-started-route",
"uri": "/get",
"methods": ["GET"],
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}Use the route create command to send this configuration to API7 EE. Note that --gateway-group (or -g) is required for runtime resource commands if not set in the current context.
a7 route create -g default -f route.jsonList your routes to see the new entry:
a7 route list -g defaultYou can also get the full details of the route you just created:
a7 route get getting-started -g defaultAssuming your API7 gateway is running and listening for data plane traffic (default port 9443), you can test the route with curl:
curl -ik https://localhost:9443/getWhen you are done, you can delete the route:
a7 route delete getting-started -g default --forceWhen you run a command that requires a resource ID without providing one, a7 presents an interactive fuzzy-filterable list:
# Instead of remembering the route ID...
a7 route get -g default
# a7 fetches all routes and presents a picker:
# > Select a route
# my-api (1)
# auth-service (2)
# health-check (3)This works for resource commands that support ID-based get, delete, and update. Interactive mode requires a terminal. In scripts or pipes, provide the ID explicitly.
You can create multiple contexts for different environments or gateway groups.
a7 context create staging \
--server https://staging.api:7443 \
--token YOUR_STAGING_TOKEN \
--gateway-group staging-groupTo see all available contexts:
a7 context listExample output:
NAME SERVER GATEWAY GROUP CURRENT
local https://localhost:7443 default *
staging https://staging.api:7443 staging-groupTo switch between contexts, use context use:
a7 context use stagingExample output:
✓ Switched to context "staging".You can verify the active context anytime:
a7 context currentYou can delete or export multiple resources with one command.
# Delete all routes in the current gateway group
a7 route delete --all --force -g default
# Export upstreams by label as JSON
a7 upstream export --label team=platform --output json -g default- Check the Configuration Guide for detailed configuration options.
- See the Route Management Guide for comprehensive route CRUD operations.
The a7 CLI supports shell completion for bash, zsh, fish, and PowerShell.
# Load completions in current session
source <(a7 completion bash)
# To load completions for every session (Linux)
a7 completion bash > /etc/bash_completion.d/a7
# To load completions for every session (macOS with Homebrew)
a7 completion bash > $(brew --prefix)/etc/bash_completion.d/a7# Enable shell completion if not already done
echo "autoload -U compinit; compinit" >> ~/.zshrc
# Generate and install completion
a7 completion zsh > "${fpath[1]}/_a7"You will need to start a new shell for this to take effect.