Capture Examples
Below are some examples using various tools to generate Capture traffic. Since Capture works by configuring a reverse proxy to forward traffic to your API, any tool that allows you to configure where requests are sent can be used.
To make it easier to send traffic to Capture's proxy, a variable is injected into server.command
's environment. By default, this variable is OPTIC_PROXY
, but can be modified as necessary by setting a value for server.proxy_variable
.
By default, Capture's proxy will be listening on localhost:8000
. A higher port number may be chosen if 8000 is in use. Alternatively, you can choose a specific port via the --proxy-port
CLI option.
Optic
The simplest example is using Optic to send traffic to your API by defining requests directly in your optic.yml
file. This is a fine place to start if you have a small surface area to cover or don't have an OpenAPI file yet and want to get one created quickly.
capture:
openapi.yml:
server:
command: npm run start-server
url: http://localhost:8080 # where your API is expected to be listening once started
requests:
send:
- path: /
- path: /widgets
- path: /widgets/create
method: POST
data:
name: widget1
Curl
#!/usr/bin/env sh
curl -s "$OPIC_PROXY"/widgets
curl -s -XPOST "$OPTIC_PROXY"/widgets/create \
-H 'Content-Type: application/json'
-d '{"name": "widget1"}'
capture:
openapi.yml:
server:
command: npm run start-server
url: http://localhost:8080
requests:
run:
command: sh ./requests.sh
Hurl
https://hurl.dev (opens in a new tab)
GET {{OPTIC_PROXY}}/widgets
POST {{OPTIC_PROXY}}/widgets/create
{"name": "widget1"}
capture:
openapi.yml:
server:
command: npm run start-server
url: http://localhost:8080
requests:
run:
command: hurl ./*.hurl # globbing is supported!
proxy_variable: HURL_OPTIC_PROXY # hurl only exposes env vars with a HURL_ prefix
HTTPie
https://httpie.io (opens in a new tab)
#!/usr/bin/env sh
# HTTPie doesnt support defining requests in a dedicated file, but we can still script it
CMD="http"
OPTS="--ignore-stdin"
"$CMD" "$OPTS" "$OPTIC_PROXY"/
"$CMD" "$OPTS" "$OPTIC_PROXY"/widgets
"$CMD" "$OPTS" POST "$OPTIC_PROXY"/widgets/create name=widget1
capture:
openapi.yml:
server:
command: npm run start-server
url: http://localhost:8080
requests:
run:
command: sh ./httpie.sh