Skip to content
Weik.ioDocs
2026.2
Try Weik.io

Publish an API and call it

Weik.io 2026.2

Publish an API from two YAML documents and call it on the gateway with a subscription's key. Product page · Video

Watch: Publish an API and call it, 3:55

The video publishes an API in front of an integration and deploys it to production. Then it calls the API with curl.

On this page

You write an API in YAML documents and publish them with weikio apply.

Kind What it is
api The product you publish. It has a name and a URL prefix.
api-version One version of the API, which either sends the calls to an upstream or receives webhooks. A version isn’t served anywhere until you deploy it.
api-deployment A version served in one environment, on that environment’s gateways.
api-subscription A caller’s access in one environment. It sets how the caller signs in and how often it may call.

Write the API#

The invoices API puts a gateway in front of the ERP’s invoice endpoints:

finance/apis/invoices.yaml
apiVersion: weik.io/v1
kind: api
metadata: { name: invoices, project: finance }
spec: { displayName: Invoice API, prefix: /invoices }
---
apiVersion: weik.io/v1
kind: api-version
metadata: { name: v1, project: finance, api: invoices }
spec:
  type: proxy
  rateLimit: { permitLimit: 1200, window: 1m }
  routes:                                   # YARP RouteConfig, as it is
    - RouteId: pending
      Match: { Path: "/{**rest}" }
      ClusterId: erp
  clusters:                                 # YARP ClusterConfig, as it is
    - ClusterId: erp
      LoadBalancingPolicy: RoundRobin
      Destinations:
        erp: { Address: "{{erp-url}}/api/invoices" }

routes and clusters go unchanged to YARP, the .NET reverse proxy that runs inside the gateway, so YARP’s documentation applies to them. The upstream’s address is a placeholder, so devtest and production send the calls to their own ERP. Upstreams and routes has the rest of the version’s fields.

To start from a scaffold, run weikio init invoices --kind api --project finance. It writes the API and a proxy version that points at an example service until the environment has a value for its address.

Apply it#

If the finance project doesn’t exist yet, create it first with weikio project create finance.

Terminal
$ weikio apply -f ./finance/apis/
You see
Target: https://hub.example, project finance (document), environment devtest (context)
api finance/invoices created
api-version finance/invoices@v1 created (type proxy, rate limit 1200/1m)

finance/invoices@v1 isn't deployed yet. To deploy it, run:
  weikio api deploy finance/invoices@v1 --env devtest

A broken route or cluster fails the apply, before it reaches a gateway.

Deploy it#

Give erp-url a value in devtest before the deploy and in production before the promote. The promote also needs a production environment with a gateway that has a hostname. weikio api deploy serves the version’s current definition on an environment’s gateway. weikio api promote then serves the same definition in production:

Terminal
$ weikio variable set finance/erp-url http://erp.example --env devtest
$ weikio api deploy finance/invoices@v1 --env devtest
$ weikio variable set finance/erp-url http://erp.example --env production
$ weikio api promote finance/invoices@v1 --from devtest --to production -y
You see
Target: https://hub.example, project finance (argument), environment production (--to)
api-deployment production/finance/invoices@v1 created (gateways internal, definition 58cd4ccee679, revision 89)
Served at https://api.example.com/invoices/v1 (gateway internal).

The API’s address, https://api.example.com/invoices/v1, is the gateway’s hostname followed by the API’s prefix and the version. Each environment has its own hostnames, so devtest serves the same API at https://api-test.example.com/invoices/v1.

While the hub is down, the gateway keeps serving the last deployment of each API.

/apis/finance/invoices
The Overview of the invoices API with its calls of the last 24 hours in production. Version v1 is served in devtest at https://api-test.example.com/invoices/v1/ and in production at https://api.example.com/invoices/v1/. The rate limit is 1200 calls a minute.The Overview of the invoices API with its calls of the last 24 hours in production. Version v1 is served in devtest at https://api-test.example.com/invoices/v1/ and in production at https://api.example.com/invoices/v1/. The rate limit is 1200 calls a minute.The Calls card of the invoices API with its calls of the last 24 hours in production, the share of failed calls, the response time and the calls per hourThe Calls card of the invoices API with its calls of the last 24 hours in production, the share of failed calls, the response time and the calls per hour
In an API's Overview, you see the version and the address each environment serves. You also see the last 24 hours of calls in one environment.

Call it#

A caller needs a subscription. Create one with an API key, which the CLI prints once:

Terminal
$ weikio subscription create finance/partner-x --env production --api invoices --type apikey --rate-limit 60/1m -y
You see
Target: https://hub.example, project finance (argument), environment production (--env)
api-subscription production/finance/partner-x created (gateway internal, type apikey, APIs invoices, rate limit 60/1m)

To rotate the key later:
  weikio subscription rotate-key finance/partner-x --env production

API key (shown once): ****************************************

Then call the API with the key in the X-Api-Key header:

Terminal
$ curl -H "X-Api-Key: $PARTNER_KEY" https://api.example.com/invoices/v1/pending

A call with no credential, or with a credential that no subscription of the API has, gets 401 with an empty body and a WWW-Authenticate header for each kind of credential the API’s subscriptions accept.

The traceresponse header of each response leads to the call’s trace, as Watching the calls shows.

Edit and deploy again#

A deployment serves the definition the version had when you deployed it. After you change the version and apply it, the apply prints the deploy command for each environment that serves an older definition:

You see
Target: https://hub.example, project finance (document), environment devtest (context)
api finance/invoices unchanged
api-version finance/invoices@v1 updated (type proxy, rate limit 1200/1m)

finance/invoices@v1 in devtest serves an older definition. Deploy it with:
  weikio api deploy finance/invoices@v1 --env devtest

finance/invoices@v1 in production serves an older definition. Deploy it with:
  weikio api deploy finance/invoices@v1 --env production

Values and secrets aren’t part of the definition, so a changed erp-url reaches the gateway without a new deploy.

Sign in to the live demo

Sign in with the shared viewer account. It can open every screen of the example projects but can't change anything.

E-mail
viewer@demo.weik.io
Password
try-weikio-live-demo
Open the live demo