Version 1.0 of the Kipchak command-line tool adds a Kipchak driver or middleware to an API in one command. It installs the package, copies its configuration into the project, initialises it in the right place, and initialises any Kipchak driver it depends on.
kipchak add anthropic
Created config/kipchak.http.php
Created config/kipchak.anthropic.php
Modified drivers/drivers.php
Set these before using it:
config/kipchak.anthropic.php: ANTHROPIC_API_KEY
The Anthropic driver makes its requests through Kipchak’s HTTP driver, so the command initialises the HTTP driver first. The API therefore works on its first request once the key is set.
What the command writes
Adding a package to a Kipchak API takes four steps: install it with Composer, copy its configuration file into
config/, initialise it in drivers/drivers.php or middlewares/middlewares.php, and do the same for any driver it
depends on. Each step is documented on the package’s page, and each is easy to get wrong: a configuration file under
the wrong name, a driver initialised before the driver it uses, or a middleware in a position where it runs before
the information it needs exists.
kipchak add performs all four. It writes plain code into the project’s own files, so the API does not depend on the
tool at run time. It never overwrites a file, and --dry-run shows every change before anything is written.
Middleware is placed in the order each package documents. Metering and Quotas, for example, are placed before the authentication middleware, so that they run after it and know who the caller is; the firewall is placed after it, so that it runs first. All of them are placed between the two Error middleware lines that every Kipchak API now has.
Every Kipchak driver and middleware, free and Enterprise, now declares its configuration file, its initialisation
and its order in its own composer.json. The command reads that information, and so can any other tool.
Creating a project
kipchak new my-api creates a project from the starter, as composer create-project does. Projects created from
starter 4.2 include the command-line tool as a development dependency. In an existing project, it is added with
composer require --dev kipchak/cli.
A later release adds commands that generate data transfer objects, controllers and resources, and that check the OpenAPI document against the routes the API registers.
The command-line tool documentation describes every command and option. The tool is MIT-licensed, and its source is mirrored to GitHub.