How to use Postman Mock Server

I followed the guide here to create a postmaster layout for a postman collection. The layout seems to have been successfully created, but I don't know how to use the service layout.

I was given the url for the layout, but how do I specify one of my requests? If I issue a GET request for https://{{mockid}}.mock.pstmn.io

, I get the following response:

{
    "error": {
        "name": "mockRequestNotFoundError",
        "message": "We were unable to find any matching requests for the mock path (i.e. undefined) in your collection."
    }
}

      

According to the same pointer mentioned above , the following url is to "start the layout" https://{{mockId}}.mock.pstmn.io/{{mockPath}}

, but what is it mockPath

?

I have a lot of folders in my collection and inside one of these folders I have a request with an example response. How can I access this example answer via layout? Thanks for any help in advance!

Here's a Postman Pro API that doesn't mention much more than just creating read mocks.

+3


source to share


2 answers


If in this example you are requesting GET

on api.domain.com/api/foo

, then mockPath will be /api/foo

, and your mock endpoint will be the GET

call https://{{mockid}}.mock.pstmn.io/api/foo

.

methods of the HTTP request and the path as shown in the image below is the layout.

breaking url



For ease of use, the layout server is designed to be used on top of collections. The examples query is used in the same way as the accompanying answer. The folder or collection name is not part of the path name and is not considered anywhere in the layout. Mocking a collection means mocking all of the examples within your collection. An example is a request and response tuple.

The optional response status code, if provided, allows for a corresponding response for the same path. This can be indicated by the title x-mock-response-code

. Thus, passing x-mock-response-code

as 404

will return an example that matches the path name and has a response with a status code 404

.

Currently, if there are examples with the same path but different domains and the mock cannot distinguish them, it will deterministically return the first one.

+3


source


I had the same problem as the error, but finally I found a solution. Unfortunately, I cannot find the link on the Postman site. But here's my solution:

When you create a Mock server, you define your first request (for example GET api / v1 / about). This way the mock server will be created, but even when you get your API key and put it in the request header (like x-api-key) it still returns an error. It doesn't make sense, but it turns out that defining the query isn't enough. For me, it was just starting to return a response when I added an example for the request.

Therefore, I suggest creating at least one example for each query you create. The request you submitted will be matched against the examples you created and an appropriate response will be returned. You can define the body, headers and HTTP status code in the example response. ...

I don't have a Pro Postman subscription and it worked for me using my free subscription.



Menu for adding an example or selecting one of them for editing: enter image description here

UI for defining an example (see body, headers, and status): enter image description here

How to return to the request page: enter image description here

Here is the correct answer I get based on my example: enter image description here

+1


source







All Articles