Mock server commands

View as Markdown

This topic covers mock server commands for the Postman CLI.

postman mock run

You can use the postman mock run command to start a mock server from a configuration file.

To run a collection against a mock server, use the --mock option with the postman collection run command.

This command starts a mock server from a configuration file in JSON format. With the configuration file, you can configure details like the mock server’s port number, name, script, and more. The mock server runs on the specified port until you stop it. Make sure you also have a JavaScript file with an HTTP server that sets the request and example response for simulating real API behavior.

Add the command to your CI/CD script to start a mock server as a dependency for your application or test suite. Once running, your service or external tests can send requests to it as if it were a real API. This enables you to simulate API behavior for testing and development.

Learn how to create a mock server in your Git repository.

Usage

$postman mock run <config-file>
<config-file>

The path to the mock server configuration file in JSON format.

Example

$postman mock run mock-config.json

Learn more at Mock APIs.