Configuration as code¶
How-to guideThe steps for one task.
The whole configuration is one apinx/v1 YAML document. Export it, keep it in a repository,
review changes as pull requests, and deploy from CI. The console and the file are two views of
the same draft; importing your own export changes nothing.
The loop¶
# capture what is deployed
apinxctl export > gateway.yaml
git add gateway.yaml && git commit -m "orders API: add rate limit"
# in CI, on merge
apinx gateway validate gateway.yaml # local, no server needed
apinxctl import gateway.yaml
apinxctl diff # what will change, for the log
apinxctl publish -m "$CI_COMMIT_TITLE"
import replaces the draft; publish deploys every changed unit. Object identifiers are kept
by name, so links, dashboards and audit history survive the round trip.
One object at a time, in the console¶
Every object of the draft can also be read and written as YAML on its own, without touching the rest. The console checks the document against the server as you type, shows what saving would change, and saves in one step; nothing is written when anything is invalid.
| Object | Where in the console | kind |
|---|---|---|
| API with its operations and policies | APIs → API → Code | API |
| One operation of an API | APIs → API → Operations → Edit → Code (YAML) | Operation |
| Upstream | Upstreams → New upstream / Edit → Code (YAML) | Upstream |
| Listener | Admin → Listeners → New listener / Edit → Code (YAML) | Listener |
| Shared flow | Shared flows → flow → Code, or Paste YAML on the list | SharedFlow |
| Product with its plans | Products → product → Code, or Paste YAML on the list | Product |
A document is the object as it appears in a gateway file, with two lines on top:
apiVersion: apinx/v1
kind: Upstream
name: partner
targets:
- url: https://api.partner.example
tls:
server_name: api.partner.example
The Code view also accepts the object as a gateway file writes it, so every sample in this
documentation pastes as it is: a fragment such as upstreams: with one entry, a whole
kind: Gateway file holding just that one object, or the object's fields alone without
apiVersion and kind. A file with several objects belongs in Admin → Import & export;
the Code view says so instead of guessing.
The Code view shows every setting, defaults included, so it is also the place to discover and
change settings the forms do not show (TLS to a backend, retry budgets, listener limits, extra
certificates). The Admin API offers the same: GET, PUT and POST …/definition/check on
/api/v1/{upstreams|listeners|shared-flows|products|routes}/{id}/definition, and
POST /api/v1/{collection}/definition to create.
Admin → Import & export works on the whole draft instead: an import replaces everything,
so use it for a complete file from apinxctl export, never for a single object.
What the file contains¶
Listeners, upstreams, APIs with their operations and policies, shared flows, flow hooks, global and environment policies, products with plans. Version and lifecycle fields of APIs are included as they are; header-selected versions and deprecation policies are derived and never need to be written by hand.
What it does not contain¶
- Consumers: applications, keys, allowed sources, subscriptions are data, changed without a deployment, and are not part of the configuration document.
- Secrets: sealed fields (backend credentials, JWT shared secrets) are exported as references to the encrypted value, never in clear. A file that sets a secret in clear is accepted on import and sealed on save.
- Users and sign-in settings.
Reviewing changes¶
apinxctl diff prints a unified diff of the compiled configuration, the same one the console
shows under Review changes, so a reviewer sees exactly what the gateway will run, including
what shared flows and hooks expand to.
Several environments¶
Today an instance is one environment. Promote by exporting from one instance and importing into another; environment-specific values (upstream addresses, origins) are the usual candidates for templating in your pipeline. Multiple environments with promotion inside one control plane are on the roadmap.
Seeding a fresh install¶
An empty store imports gateway.yaml from the working directory (or proxy.config_file) on
first start and deploys it as revision 1; from then on the store is the source of truth and the
file is an export format.
No store at all¶
apinx gateway run gateway.yaml serves the file alone, watched and reloaded, with no store and
no console: the shape a Kubernetes ConfigMap or a GitOps pipeline expects. The file may reference
environment variables (${ORDERS_URL}, ${PORT:-8080}). See
Run from a file, no database.