Web Analytics

mock

⭐ 170 stars English by dhuan

mock

Go Reference Go Report Card

mock is an API utility - it lets you:

command-line parameters. as response handlers. The fastest way to learn and understand mock is to see the examples page.

Quick links

Getting started

$ mock serve --port 3000 \
  --get "/time-now" \
  --exec 'printf "Now it is %s" $(date +"%H:%M") | mock write' \
  --post "/shut-down/{application}" \
  --exec 'killall $(mock get-route-param application)'
Let's test it out:

$ curl localhost:3000/time-now

Prints out:

Now it is 22:00

$ curl -X POST localhost:3000/shut-down/mock

Shuts down the server!

mock also lets you extend other APIs (or any HTTP service, for that matter.) Suppose you want to add a new route to an existing API running at `example.com:

$ mock serve --port 3000 \
  --base example.com \
  --get 'some-new-route' \
  --exec 'printf "Hello, world!" | mock write' 
With the
--base example.com option above, your API will act as proxy to that other website, and extend it with an extra route GET /some-new-route`. Look up "Base APIs" in the docs for more details.

There are many other ways of further customising your APIs with mock. Read further through the guide to learn.

Installing

mock is distributed as a single-file executable. Check the releases page and download the latest tarball.

License

mock is licensed under MIT. For more information check the LICENSE file.

--- Tranlated By Open Ai Tx | Last indexed: 2026-07-18 ---