# Introducing support for templating in Postman mock servers

We're continuously striving to advance the [Postman API Platform](https://www.postman.com/api-platform/) with the tools and solutions that will help you build your APIs easily and better accomplish your goals. With that mission in mind, we’ve now added support for templating in [mock servers](https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/setting-up-mock/ "https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/setting-up-mock/"), enabling you to get contextual responses to mock requests quickly.

In this blog post, we’ll quickly show how you can define collection examples using template helpers and what is now available for you as part of these helpers. Let’s get started.

## Helpers that you can use while defining templates

- `$body`
- `$queryParams`
- `$pathSegments`
- `$headers`
 
 The helpers mentioned above give you access to the request data sent to the mock server. You can use [object-path](https://www.npmjs.com/package/object-path "https://www.npmjs.com/package/object-path") syntax to access specific values on these helpers, and you can also define a default value for a key that will get used if the mock server can’t resolve the variable. ### Examples

 ```
{{$body}} - Access the complete request body
{{$body 'path.to.property'}} - Access a specific property from body
{{$body 'path' 'default value'}} - Define a default value for a property
{{$body 'a\.a'}} - Access a.a key from the body, which itself has a '.' in the key

// Similar syntax can be used with queryParams, pathSegments and headers.
```

## Defining collection examples using templates

Step 1. Create a collection.

 ![](https://blog.postman.com/wp-content/uploads/2022/11/Screenshot-2022-11-29-at-3.28.58-PM-300x146.png)You can use the New or + button to create a collectionStep 2. Add a request to the collection.

 ![](https://blog.postman.com/wp-content/uploads/2022/11/Screenshot-2022-11-29-at-3.36.06-PM-300x145.png)Add a request to the collectionStep 3. Define an example using helpers.

 ![](https://blog.postman.com/wp-content/uploads/2022/11/Screenshot-2022-11-29-at-3.46.52-PM-1000x487.png)Utilize `$body` helper to access the username key in the example response Step 4. [Create a mock server](https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/setting-up-mock/ "https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/setting-up-mock/") on the collection. ![](https://blog.postman.com/wp-content/uploads/2022/11/Screenshot-2022-11-29-at-3.52.55-PM-1000x485.png)Create a mock server on the Login API collectionStep 5. Call the mock server with any request data combinations.

 ![](https://blog.postman.com/wp-content/uploads/2022/11/Screenshot-2022-11-29-at-3.54.39-PM-1000x485.png)The username key in response was resolved using the request’s username value [**Try Postman now**](https://www.postman.com/downloads/ "https://www.postman.com/downloads/")