This topic covers mock server commands for the Postman CLI.
postman mock runYou can use the postman mock run command to start a local 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 local 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 more at Simulate your API using a Git-backed mock server.
The path to the mock server configuration file in JSON format.
Specifies the path to an environment file (JSON or YAML) loaded into pm.environment for the mock server’s scripts.
Specifies the path to a globals file (JSON or YAML) loaded into pm.globals for the mock server’s scripts.
Learn more at Mock APIs.