Starts and Optic service locally to receive traffic from middleware integrated with your code, and starts your project.
exec allows you to run any project in any environment and capture traffic. It takes the command to start your project as a required parameter.
You can also take the command to start your project and define a task in
optic.yml with only a
command parameter. This task can be run with
api run <taskname> and it will behave just like
api exec. Please check out an example
Exec has a few flags that can modify the default behavior:
--print-coverageprints how much of the documented API is covered by traffic seen in the capture session. The coverage prints once the session is terminated (
ctrl+cor when tests finish running).
--ciEnables CI-specific behavior. This enables
--exit-on-diffreturns an exit code of
1if unexpected API behavior is returned, such as an undocumented route or a change in behavior on a documented route. Normally, Optic returns
0on successful termination regardless of the behavior observed. This is primarily used in CI/CD scenarios, such as in GitHub Actions, to fail builds when undocumented behavior is detected.
--pass-exit-codereturns the exit code of your task. If you are using a dependent task, the exit code of the dependent command (not the base command) will be passed through. This flag is overridden by - - -
--verbosewhich provides extra troubleshooting information at task startup, task end, and when traffic is observed. We recommend using this when configuring a new task.
api exec "cargo run"
Running command: node basic-http-server.jsTraffic can be sent to: http://localhost:3700/ ...
api run start
name: "todo-js"tasks: start: command: node server.js
Having trouble? Open an issue on GitHub
Have an idea for changing this command? Here's where it lives in the repo. PRs welcome!
Need help or want to talk with us about a use case? Join Contributing on Discord