environment is a way to automatically configure a proxy, often against a remote target. You only need to define the target
host. Traffic to
environments is observed with the api intercept command. Optic will set up a local proxy, launch a new session of the browser of your choice (passed as a command line flag), and configure the new browser session to trust the Optic proxy. You then interact with your API project just as you would normally.
environments are designed to have minimal configuration for ease of use, and are generally intended to run against remote targets whose lifecycles you don't control locally. If you need more configurability, or your project runs locally, consider using a task.
What parameters are available when defining an
host: The URL of the host against which Optic will log all traffic. Optic will ignore traffic to other hosts, which reduces noise when reviewing traffic in the Optic dashboard
webUI(optional): When opening the web browser, Optic will launch this page. This is not required, but is a handy way to launch a web UI for your project. This only launches a page in the browser, and has no effect on the
hostdefinition for capturing traffic.
name: "GitHub"environments: github: # Opens a browser configured to pass traffic through a local Optic proxy. No default URL will be loaded. # run with api intercept github --chrome host: https://api.github.com
name: "GitHub"environments: production: # Manually browse through the GitHub API and capture all the traffic starting at Optic's repository! # run with api intercept production --chrome host: https://api.github.com webUI: https://api.github.com/repos/opticdev/optic
name: "todo-js"environments: staging: # Capture traffic to your staging API server while browsing your staging webapp. # run with api intercept github --chrome host: https://staging.api.myapp.com webUI: https://staging.myapp.com