Link

Configuring Captures

Optic Tasks

When you first setup Optic, a start task is added to your optic.yml file. The start task can be run using api start


name: Todo API
tasks:
  start:
    command: npm run server-start
    baseUrl: 'http://localhost:3005'

You may also want a quick way to run your API tests, a Postman collection, etc through Optic. To make this simple, Optic lets you define as many custom tasks as you’d like:

name: Todo API
tasks:
  start:
    command: npm run server-start
    baseUrl: 'http://localhost:3005'
  test:
    command: npm run testAPI
    baseUrl: 'http://localhost:3005'

Each custom task can be run with api run <task name>.

Ignoring API Paths

As you use Optic, you will probably find there are some paths you would like Optic to ignore. Examples include OPTIONS requests, .html, .js, .css files, or everything in your /public folder.

You can add ignore rules to your api.yml file:

name: Todo API
tasks:
  start:
    command: npm run server-start
    baseUrl: 'http://localhost:3005'

ignoreRequests:
- OPTIONS *
- GET /public/**

Rules follow a simple format: METHOD(s) path

  1. The methods component can be:
    • a single method GET
    • multiple methods GET POST PUT
    • omitted -> which is interpreted as ALL
    • * -> which is interpreted as ALL
  2. The path component follows the path-to-regex format. The library has a lot of advanced features that you can use, but most use cases can probably be acomplished with the following patterns:
    • Want to ignore an absolute path? Just write it ie /users/profile
    • Want to ignore a file type? ie **.png **.js
    • Want to ignore a path and its children? /public/**
    • Need something more advanced? Try creating your pattern in the path-to-regex-sandbox

Examples

ignoreRequests:
  - OPTIONS *               # Ignores all Options requests
  - * /public/**            # Ignores all Requests to public/**
  - GET **.js               # Ignores all GET requests to a resource ending in .js
  - GET POST PUT /resource  #Ignores all GET, POST, PUT requests to /resource