The gateway on a laptop
Weik.io 2026.2Run the gateway alone on a laptop on plain HTTP and try an API and the gateway's rules on your own machine.
On a laptop the gateway runs alone on plain HTTP, with no front server and no certificate. It runs the same code as a hub gateway and a site gateway. Use it to try an API and the gateway’s rules on your own machine.
Start it#
The gateway needs the hub’s message server and a credential of its own, apim-1.creds, which weikio-backend init writes into the keys directory. The Try Weik.io dev container has both. When you open the container, the gateway starts beside the backend on plain HTTP.
The gateway accepts calls on http://localhost:8581, and every call there arrives on the entrance public. Run the commands on this page in the dev container’s terminal, where that address answers.
When the gateway starts while the message server is away, it serves a copy of the last route tables it received.
Call an API without setup#
weikio-backend init --dev creates a gateway called devtest in the environment devtest, with these settings:
- It’s the environment’s default gateway.
- It answers on the entrance
public. - It’s open to every caller.
- Its hostname is
localhost.
Because it’s the default, a deploy and a subscription need no gateway named, and you call the gateway on the local port:
$ weikio apply -f ./hello-api.yaml
$ weikio api deploy sandbox/hello@v1 --env devtest
$ weikio subscription create sandbox/me --env devtest --api hello --type apikey
$ curl -H "X-Api-Key: <the key it printed>" http://localhost:8581/hello/v1/worldThe hostname localhost answers on any local port, and Weik.io orders no certificate for it. When the installation’s address is localhost, which no gateway may use, init creates the gateway with no hostname and prints the command that adds the name you call it by.
To start an API of your own, weikio init hello --kind api --project sandbox writes hello/hello.yaml with the API and a proxy version.
The edit loop#
A deployment serves the definition it pinned when it was deployed. After you edit a version with weikio apply or in the admin UI’s editor, weikio apply prints each environment that serves an older definition, with the line that deploys it:
sandbox/hello@v1 in devtest serves an older definition. Deploy it with: weikio api deploy sandbox/hello@v1 --env devtest
Run that line, or press Deploy on the API’s page, and the gateway serves the edit from its next route table. Values and secrets aren’t pinned, so a changed value reaches the gateway without a new deploy.
In a repository, write the devtest api-deployment without a definition and apply it with the version. Each apply then deploys the current definition.
Try the rules#
The rules a hub gateway enforces work on the laptop too.
Who may connect#
The gateway admits a caller by the address the connection comes from. Linux answers on all of 127.0.0.0/8, so a gateway created with --networks 127.0.0.1/32 refuses curl --interface 127.0.0.2 ... and serves curl from 127.0.0.1. A refused caller gets the same reply as a call to a name that doesn’t exist.
TLS and client certificates#
Start the gateway with an HTTPS address, such as --urls https://localhost:8443, and it terminates TLS itself. Then create a second gateway that asks for client certificates, and upload a test certificate for its name:
$ weikio gateway create partner-local --env devtest --hostname partner.localhost --networks 127.0.0.0/8 \
--client-certificate required --authority test=test-ca.pem --server-certificate local=partner.localhost.pem,partner.localhost.key
$ weikio subscription create sandbox/partner --env devtest --gateway partner-local --api hello --type certificate \
--certificate-authority test --certificate-name partner.example
$ curl --cacert test-ca.pem --cert partner.pem --key partner.key --resolve partner.localhost:8443:127.0.0.1 \
https://partner.localhost:8443/hello/v1/worldOnly devtest is the default gateway, so deploy the API onto partner-local by name with weikio api deploy sandbox/hello@v1 --env devtest --gateways devtest,partner-local. After you revoke a certificate with weikio gateway set partner-local --revoke-certificate test=partner.pem, the gateway refuses it from the next route table on.
An internal entrance#
An entrance is a separate listener. Add one at install with weikio-backend init --dev --apim-entrance internal=127.0.0.1:8444, and start the gateway with both listeners. A gateway created with --entrance internal then answers only on 8444, and a gateway of the entrance public answers only on its port.
Limits across APIM instances#
Start a second gateway process against the same message server with WEIKIO_APIM_INSTANCE=2. Give it a WEIKIO_HOME and a port that the first process doesn’t use.
A subscription’s limit applies across both processes. When you stop one, the other keeps counting the same window.
A site gateway#
A site gateway’s APIM instance is one more gateway process. Start it from the gateway.env of its bundle, against the message server beside it on the laptop.