Control API OpenAPI Spec ↗
import { Commander } from 'mockaton'
const mockaton = new Commander('http://localhost:2020')
patch /mockaton/reset Re-initialize Mockaton
The selected mocks, cookies, and delays go back to default, but proxyFallback, collectProxied, and corsAllowed are not affected.
await mockaton.reset()
curl http://localhost:2020/mockaton/reset \
--request PATCH
patch /mockaton/bulk-select-by-comment Select all mocks that have a particular comment
await mockaton.bulkSelectByComment('(demo-a)')
curl http://localhost:2020/mockaton/bulk-select-by-comment \
--request PATCH \
--data '"(demo-a)"'
patch /mockaton/select Select a mock file for a route
await mockaton.select('api/user/avatar.GET.json')
curl http://localhost:2020/mockaton/select \
--request PATCH \
--data '"api/user/avatar.GET.200.svg"'
patch /mockaton/toggle500 Toggle 500 for a route
Selects the first found 500, which could be the autogenerated one. Or, selects the default file.
await mockaton.toggle500('GET', '/api/user/friends')
curl http://localhost:2020/mockaton/toggle500 \
--request PATCH \
--data '["GET","/api/user/friends"]'
patch /mockaton/proxied Set whether a route is proxied
Applicable only when there’s a proxy fallback server URL already set. See PATCH /mockaton/fallback
await mockaton.setRouteIsProxied('GET', '/api/user/friends', true)
curl http://localhost:2020/mockaton/proxied \
--request PATCH \
--data '["GET","/api/user/friends",true]'
patch /mockaton/delay Set whether a route is delayed
await mockaton.setRouteIsDelayed('GET', '/api/user/friends', true)
curl http://localhost:2020/mockaton/delay \
--request PATCH \
--data '["GET","/api/user/friends",true]'
patch /mockaton/static-status Set static HTTP status for a route
await mockaton.setStaticRouteStatus('/media/picture.png', 404)
curl http://localhost:2020/mockaton/static-status \
--request PATCH \
--data '["/media/picture.png",404]'
patch /mockaton/delay-static Set static delay flag for a route
await mockaton.setStaticRouteIsDelayed('/media/picture.png', true)
curl http://localhost:2020/mockaton/delay-static \
--request PATCH \
--data '["/media/picture.png",true]'
patch /mockaton/global-delay Set global delay for all responses
await mockaton.setGlobalDelay(1500)
curl http://localhost:2020/mockaton/global-delay \
--request PATCH \
--data '1500'
patch /mockaton/cors Enable or disable CORS
await mockaton.setCorsAllowed(false)
curl http://localhost:2020/mockaton/cors \
--request PATCH \
--data 'false'
patch /mockaton/fallback Set proxy fallback address
await mockaton.setProxyFallback('http://example.com')
curl http://localhost:2020/mockaton/fallback \
--request PATCH \
--data '"https://example.com"'
patch /mockaton/collect-proxied Enable or disable collection of proxied responses
Applicable only when there’s a proxy fallback server URL already set. See PATCH /mockaton/fallback
await mockaton.setCollectProxied(true)
curl http://localhost:2020/mockaton/collect-proxied \
--request PATCH \
--data 'true'
patch /mockaton/cookies Select a cookie label
await mockaton.selectCookie('Normal User')
curl http://localhost:2020/mockaton/cookies \
--request PATCH \
--data '"Normal User"'
get /mockaton/state Get complete Mockaton state
await mockaton.getState()
curl http://localhost:2020/mockaton/state
get /mockaton/sync-version Get sync version for long‑polling updates
A counter that’s incremented when a new mock is added, removed, or renamed.
await mockaton.getSyncVersion()
curl http://localhost:2020/mockaton/sync-version