Optic documents your APIs as you build them by observing development traffic and learning your API's behavior. The CLI is constantly diffing your API’s behavior against its specification; ensuring every change to the API gets detected, documented and code reviewed by your team.
How does Optic monitor local traffic? Optic observes API and diffs API traffic in the background when you're building your API. All you have to do is start using API CLI to start your API + run your tests ie
api start or
api run postman-tests.
- Changes to tracked endpoints (ie a new field, or a changed type) are detected by Optic. With one click, Optic will help you update the specification.
- Document new endpoints in seconds (just like "git add" source files).
api start alias#
From your API project, run:
You can use the guided setup flow that
api initopens, or follow along below.
Task Aliases are configured in the
The first task you should set up is
start. When your run
api start or
api run start Optic will run the
command to start your API on
For the start task:
commandshould start a long-running process, that binds to
localhoston a specific
$PORT(injected as an environment variable)
inboundUrlshould be set to where you start your API today
Make sure your API starts on $PORT
Optic assumes your API can be started on a specific port, which Optic assigns. To do this, Optic provides $PORT as an environment variable. You'll either need to map this variable to a flag your API framework looks for, or modify your code to look for the $PORT variable when starting up.
on Windows, optic.yml commands are interpreted by the Command shell
By default, Node uses the built-in Command shell on Windows when asked to start a child process. This interprets commands differently from bash. Tools like cross-env help manage this for cross-platform projects. On Windows only projects, you can target Command shells directly. Here's a few Windows tips:
- To expand an environment variable such as
- When invoking a program or script, use Command shell format (for example,
./applicationon Linux/MacOS would be