Fiko Borizqy
Fiko Borizqy

Fiko Borizqy

How to Setup Postman Mock Server

Fiko Borizqy
·Aug 7, 2021·

3 min read

How to Setup Postman Mock Server

Subscribe to my newsletter and never miss my upcoming articles

Table of contents

When you’re developing a project with a third party for the API service, you must need their development / sandbox site to develop and run test instead of running the test using their (3rd party) production site. But, sometimes their sandbox is not ready or in the worst case they have no sandbox site to run the test.

You can use postman to create the mock server to run test base on the case you’d like to develop. Postman provides this feature free (of course it has limitation, mate), for more information of postman mock server limitation you can read on this page postman.com/pricing. Okay, be ready for the steps (I’m using Postman v8.10.0) :

1. Prepare Collection

image.png
Create new collection

Create new collection if you have no collection on your workspace. You may rename your new collection, in this case I rename my collection to "Mock Server".

image.png
Rename the collection Name

2. Prepare Environment

2.1. Create new Environment

You need to create new environment to handle the address. It’s not a mandatory actually, but it will make your development much easier, so just do this step on your own.

image.png
Create new environment

2.2. Create Environment Variable

In this case i’m creating base_url, so what is it? once you created a new mock server, you will have endpoint URL. We need to store this URL so you don’t have to change the endpoint URL on every request.

You don’t have to have base_url as the variable, you may use whatever you like to use. Just leave empty for the initial value & current value, why? because we haven’t setup the mock server.

image.png
reate environment variable

3. Prepare Mock Up Server

3.1. Create Mock Server

Simply just go to mock server menu.

image.png
Create Mock Server

Then configure the mock server to match with the environment we previously created.

image.png
Configure Mock Server

as the result, you will have mock server URL as your endpoint URL address.

image.png
Mock Server Result

3.2. Setup base_url

In Step 2.2 we created base_url environment variable, copy mock server URL as a value to this variable.

image.png
Setup mock server URL

4. Prepare Request

4.1. Create Request

Then once collection is ready, prepare new / existing request to handle the request. in this case, I’m creating new request called "Authentication".

image.png
Create new request

4.2. Setup Request

Then once you’ve finish creating new request, you need to setup the request. in this case, I’m creating such as a login feature by sending username & password.

image.png
Setup login endpoint

4.3. Setup Response Example

This is the main point, you need to create response example for the request.

image.png
Add new example

Then setup the response (body & header).

image.png
Setup Response

5. Test it

In this test case I hit the API by postman & terminal (just to make sure it works perfectly just like what I want).

image.png
Testing

Did you find this article valuable?

Support Fiko Borizqy by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
 
Share this