Run a mock locally and inspect its logs and state
Run a mock locally to develop against it before you deploy it. Start the mock on your machine, send requests to it at localhost, and watch its logs and state as it handles each request. To make a mock always available to your team instead, deploy it as a mock server.
The steps in this section use the Postman desktop app. To run a mock from the command line, including in CI, use the postman mock run command.
Start a mock and send local requests
Start a mock and send it HTTP requests to validate that it behaves as expected. The URL is http://localhost:<port>, where the port is specified in the mock’s settings. If the specified port is already in use, the mock falls back to an available port assigned by the OS. You can manually start and stop the mock to control when it listens for requests.
- Click the
Items tab in the sidebar.
- Click Mocks.
- Select the mock.
- Click Start in the upper right. You can also select
View more actions > Start next to a mock in the sidebar.
- In the upper right, click
Open in a new request to open a new request with the URL auto-filled. You can also click
Copy URL to copy the URL and use it in an HTTP request.
- Send requests to the URL and observe the responses.
Click Stop in the upper right to stop the mock.
You can also start a mock locally from the Postman CLI with the postman mock run command.
Inspect a running mock
View requests, responses, and state information for a running mock.
- Click the
Items tab in the sidebar, click Mocks, then select a mock.
- Use the Logs and State tabs to inspect requests, responses, and state information for the mock.
View logs
View incoming requests, responses, and state operations in the Logs tab.
You can filter logs to focus on specific requests and responses. For example, you can filter by a specific endpoint to see all requests made to that endpoint and the corresponding responses. The filters are:
- Filter path — Show requests whose path matches the text you enter.
- Type — Show Request, State, or System log entries.
- Method — Show requests that use one or more HTTP methods, such as
GETorPOST. - Status — Show responses by status class: 2xx Success, 3xx Redirect, 4xx Client error, or 5xx Server error.
- Time — Show entries from the Last 1 minute, Last 5 minutes, Last 15 minutes, or Last 1 hour.
- Header — Show requests that include a header name and value you enter.
Select a log entry to view more details about the request and response, including headers and body content.
When a behavior such as a delay, error, rate limit, or chaos mode applies to a request, its log entry shows a label for each behavior that triggered, such as delay: 2000ms.
Click Clear logs to remove all logs for the mock.
View state
If your mock uses pm.state, you can inspect the current state values in the State tab.
State entries are displayed as key-value pairs. Expand a state entry to view its contents and inspect how requests have modified state over time.
Click Delete logs and state to remove both the state values and the logs.
View mock history
Each time you start a mock, Postman records the run. Use mock history to review past runs, including who started each one, how long it ran, and the logs and state captured during the run.
Click History to view the mock’s past runs.
The history table lists each run with the following details:
Use the Started by and Source filters to narrow the list.
You can also open a mock’s past runs from the History tab in the sidebar. To learn more, see History.