# Examples vs Requests - adding mock responses to an existing collection

**URL:** <https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115>\
**Category:** Help Hub\
**Tags:** bootcamp\
**Created:** [October 1, 2019, 11:48pm UTC](https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115 "2019-10-01T23:48:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dan1/32/2931_2.png) [@dan1](https://community.postman.com/u/dan1)\
**Post date:** [October 1, 2019, 11:48pm UTC](https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115/1 "2019-10-01T23:48:52Z")

</div>

> **Archived topic — some details may be out of date.**  
> Mock servers built from saved collection examples are still supported. Postman now also has **code-based mocks** : JavaScript request handlers plus a `config.yaml`, stored as files in your Git repository, which you can run locally or deploy. Create one in the app, or use the Postman CLI to generate one from an OpenAPI spec, collection or dataset (`postman mock generate`) and run it (`postman mock run`). See [About mocks](https://learning.postman.com/docs/design-apis/mock-apis/mocks/overview) and [Create a mock](https://learning.postman.com/docs/design-apis/mock-apis/mocks/create-a-mock).  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) can build and run mocks for you.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

I’ve just completed the Bootcamp tutorial, _Designing and mocking APIs_ \> _Design an API in a minute_.

I’m confused about where I add mock responses to an existing collection.

These are the steps I followed:

I create a _New \> Mock Server_. I’m provided with a table to create a _collection_ of _requests_ and _responses_:

> Enter request paths for your API endpoints and then the expected response code and response body to create an example.

I create two items:

1. Method: `GET`  
Request Path: `hello`  
Response Code: `200`  
Response Body: `Hello world`
2. Method: `GET`  
Request Path: `goodbye`  
Response Code: `200`  
Response Body: `Goodbye, cruel world`

After clicking _Next_ I name the mock server: `Hello and Goodbye`. Then I click _Create Mock Server_ and finally _Close_ the modal.

My Collection now correctly appears with two `GET` requests: `hello` and `goodbye`.

In the _Environment_ dropdown at the top right of the UI, I choose `Hello and Goodbye`.

Now I can select one of the `GET` requests in my collection and _Send_ it, and the response is as expected/mocked.

Now. When I click on the _Examples_ dropdown, there is _Default_ and _Add Example_. This is confusing as I added two _examples_ when I created my mock server. But these two examples only appear in my (request) collection.

So I now want to add a third request to my collection. I click on the `···` menu and click _Add Request_. I only have access to the _Request name_ here, so I name it `hellohello` and save it to my collection.

When I select the new request in the collection, all of the fields are blank. I set the method to `GET` and the URL to `{{url}}/hellohello`. But where do I set the mock response?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 2, 2019, 8:59am UTC](https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115/2 "2019-10-02T08:59:09Z")

</div>

Hey @dan1,

Welcome to the Community and thank you for the question 🏆

I think I’m following you but correct me if this is not the case - when you created the Mock Server you created `1` example for each of the `2` different routes (`/hello` and `/goodbye`)

 ![54](https://us1.discourse-cdn.com/getpostman/original/3X/4/d/4d7a2473fae61a8a14e3a70c5128f13af5aee3b3.png)

That would mean that each request in your Collection would have a single example each, rather than 2 examples on a single route.

 ![28](https://us1.discourse-cdn.com/getpostman/original/3X/4/5/4583f3ba29fb9d4e7a6faf16d47ade04217b615f.png)

The first `Example` has been named as `Default` but this can be changed to anything you what by clicking on the name in the `Examples` dropdown menu.

 ![32](https://us1.discourse-cdn.com/getpostman/original/2X/b/b56f8b645821d26d5f23a083f29e198f945b3501.png)

The `Mock Creation` flow is different from the single `Add Request` flow, as this can be done as a separate action and is not tied into being used solely for the Mock Servers.

Picking things up from your empty `hellohello` request, If you go to the `examples` section again and press the `Add Example` button it will open up the `Example` builder.

 ![50](https://us1.discourse-cdn.com/getpostman/original/2X/e/e4f6ddffe5034c44b501ca8cfdbf8b6fef8935e8.png)

This will already be pre-populated with the `{{url}}/hellohello` request URL. For the most basic case, all you need to do is add a `Response Body` and a `Response Code`.

Once you press the `Save Example` button, that will now be ready to use in your actual request and return the details you provided.

 ![37](https://us1.discourse-cdn.com/getpostman/original/2X/e/e333e21cc737ab559a0fe817bec4306cc79df5f3.png)

In the main request view, you should now see the `hellohello` example in the dropdown.

 ![58](https://us1.discourse-cdn.com/getpostman/original/3X/1/6/163ad958e6fb7c27b4640e798254877dcca31cec.png)

By hitting the `Send` button, the request will be sent to the Mock Server and it will return the example request that you previously created.

 ![11](https://us1.discourse-cdn.com/getpostman/original/3X/7/e/7e053d5b516d68f6751596e4b636d026d85769cd.png)

I hope that makes sense and you’re able to follow the flow that I listed. Any questions or If you need me to clarify any of the behaviours, don’t hesitate to ask. 🙂

---

<div class="post-metadata">

**Author:** ![dan1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dan1/32/2931_2.png) [@dan1](https://community.postman.com/u/dan1)\
**Post date:** [October 2, 2019, 10:23am UTC](https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115/3 "2019-10-02T10:23:15Z")

</div>

@danny-dainton Many thanks for putting together all the screenshots and the explanation. Yes you are following me correctly.

I had a bit more of a play with it, and I now understand why each example is linked to a route, and where I went wrong.

The `Mock Creation` flow both creates the _route_ and sets up the basic parameters of the (default) _example_.

> Enter request paths for your API endpoints and then the expected response code and response body to create an example.

I’d read that as the whole table row being an example, not (A) a request path and (B) an example.

I now understand that there can be many examples for each route, because each has a plethora of customisation options and is not solely configured on the supplied route / response code / response body.

This is why the request path appears under the _Collections_ sub-heading, but the example(s) appears under the _Examples (n)_ dropdown for that request path. There can only be one of each request path, but depending on what you do or don’t send with the request, the response can be very different.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [October 2, 2019, 10:46am UTC](https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115/4 "2019-10-02T10:46:07Z")

</div>

Cool, was there anything else that you were unsure about?

---

<div class="post-metadata">

**Author:** ![dan1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dan1/32/2931_2.png) [@dan1](https://community.postman.com/u/dan1)\
**Post date:** [October 2, 2019, 10:57am UTC](https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115/5 "2019-10-02T10:57:21Z")

</div>

Not at the moment thanks. I’ve just marked your answer as the solution 🙂

---

<div class="post-metadata">

**Author:** ![josegus](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/josegus/32/9216_2.png) [@josegus](https://community.postman.com/u/josegus)\
**Post date:** [July 19, 2021, 4:57pm UTC](https://community.postman.com/t/examples-vs-requests-adding-mock-responses-to-an-existing-collection/8115/6 "2021-07-19T16:57:04Z")

</div>

2021 July update: Examples are not shown anymore in the “Example” label dropdown
