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, deploys it to production and calls it with curl.

On this page

You write an API in YAML documents and publish them with weikio apply. The documents are of four kinds:

Kind What it is
api The product you publish, with 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, with how it 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, and 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#

Terminal
$ weikio apply -f ./finance/apis/
You see
Target: https://hub.example, project finance (from finance/project.yaml)
api finance/invoices created
api-version finance/invoices@v1 created (type proxy, rate limit 1200/1m)
api-version finance/bank-notifications@v1 created (type webhook, channel bank-notification-received)
api-deployment devtest/finance/invoices@v1 created
api-subscription devtest/finance/partner-y created
Gateways updated in: devtest.

When you apply, Weik.io fills in the placeholders and checks the routes and clusters with YARP’s validator. A broken route fails at the apply, before it reaches a gateway.

The folder also has a devtest deployment and a devtest subscription. Devtest serves the API after this apply.

Deploy it#

weikio api deploy serves the version’s current definition on an environment’s gateway. weikio api promote serves in production the definition devtest tested:

Terminal
$ weikio api deploy finance/invoices@v1 --env devtest
$ 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 3f9a0c1e2b4d, revision 31)
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.

After a deploy the gateway gets a new route table. While the hub is down, the gateway keeps serving the last route table it had.

/apis/finance/invoices
The Overview of the invoices API with its calls of the last 24 hours in production, v1 served in devtest at https://api-test.example.com/invoices/v1/ and in production at https://api.example.com/invoices/v1/, and the rate limit of 1200 calls a minuteThe Overview of the invoices API with its calls of the last 24 hours in production, v1 served in devtest at https://api-test.example.com/invoices/v1/ and in production at https://api.example.com/invoices/v1/, and the rate limit of 1200 calls a minuteThe 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
An API's Overview shows the version and the address each environment serves, with 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 a response leads to the call’s trace, and Watching the calls shows how to use it.

Edit and deploy again#

A deployment serves the definition it pinned when it was deployed. After you change the version and apply it, the apply prints each environment that serves an older definition, with the line that deploys the new one:

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

Values and secrets aren’t pinned, 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, which can open every screen of the example projects and can't change anything.

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