The Wayback Machine - https://web.archive.org/web/20241127004621/https://www.geeksforgeeks.org/how-to-create-mock-servers-using-postman/
Open In App

How to create mock servers using Postman

Last Updated : 30 Apr, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Postman is a comprehensive API platform used by developers; this platform provides a set of tools that support API design, testing, documentation, mocking, and API Monitoring. It also simplifies each step of the API lifecycle and streamlines collaboration, enabling developers to create and use APIs more efficiently. Postman's API client is the foundational tool of Postman, and it enables developers to easily explore, debug, and test APIs while also enabling them to define complex API requests for HTTP, REST, SOAP, GraphQL, and WebSockets.

Prerequisites

What is a mock-server:

Mock server serves as a simulated or pseudo server that mimics authentic server behavior. They return controlled responses to requests, letting you design and create JSON API responses without writing a single line of code.

Let us assume that you are working as front-end developer in a large team that is tasked with building a web application that relies on a back-end API to fetch data. However, the back-end development is still in progress, and the API endpoints are not available yet. To avoid delays in front-end development, you decide to use a mock server in Postman.

How to create a mock servers using Postman?

Step 1: Open the postman application on your computer then click on the mock servers tab on the left side navigation bar.

WhatsApp-Image-2023-12-17-at-50529-PM

Step 2: To create a new mock server, click on the create mock server or the plus symbol beside the collections tab.

WhatsApp-Image-2023-12-17-at-51604-PM

Step 3: Create mock request

To create a sample mock request, you'll need to understand the following concept:

  • Request Method: This dropwown allows you to select our prefared http methods. example: GET, POST, PUT, DELETE
  • Request URL: This is used to specify the exact route in our mock endpoints.
  • Response Code: http response codes ranging from 100 to 599 can be used depending on our desired response
  • Response Body: This input field is used to pass a sample json response

WhatsApp-Image-2023-12-18-at-125032-AM

Now that you have understood the above concept, We are going to modify the input fields. for the purpose of this article, we will create a mock api to get the list of users in our application.

Start by setting the request url input field to users. Next copy JSON response below and paste in the response body. Then click next to continue.

JavaScript
[{
    "id" : 1,
    "name" : "Leanne Graham",
    "username" : "Bret",
    "email" : "Sincere@april.biz",
    "address" : {
        "street" : "Kulas Light",
        "suite" : "Apt. 556",
        "city" : "Gwenborough",
        "zipcode" : "92998-3874",
        "geo" : { "lat" : "-37.3159", "lng" : "81.1496" }
    },
    "phone" : "1-770-736-8031 x56442",
    "website" : "hildegard.org",
    "company" : {
        "name" : "Romaguera-Crona",
        "catchPhrase" :
            "Multi-layered client-server neural-net",
        "bs" : "harness real-time e-markets"
    }
},
 {
     "id" : 2,
     "name" : "Ervin Howell",
     "username" : "Antonette",
     "email" : "Shanna@melissa.tv",
     "address" : {
         "street" : "Victor Plains",
         "suite" : "Suite 879",
         "city" : "Wisokyburgh",
         "zipcode" : "90566-7771",
         "geo" : { "lat" : "-43.9509", "lng" : "-34.4618" }
     },
     "phone" : "010-692-6593 x09125",
     "website" : "anastasia.net",
     "company" : {
         "name" : "Deckow-Crist",
         "catchPhrase" : "Proactive didactic contingency",
         "bs" : "synergize scalable supply-chains"
     }
 },
 {
     "id" : 3,
     "name" : "Clementine Bauch",
     "username" : "Samantha",
     "email" : "Nathan@yesenia.net",
     "address" : {
         "street" : "Douglas Extension",
         "suite" : "Suite 847",
         "city" : "McKenziehaven",
         "zipcode" : "59590-4157",
         "geo" : { "lat" : "-68.6102", "lng" : "-47.0653" }
     },
     "phone" : "1-463-123-4447",
     "website" : "ramiro.info",
     "company" : {
         "name" : "Romaguera-Jacobson",
         "catchPhrase" :
             "Face to face bifurcated interface",
         "bs" : "e-enable strategic applications"
     }
 },
 {
     "id" : 4,
     "name" : "Patricia Lebsack",
     "username" : "Karianne",
     "email" : "Julianne.OConner@kory.org",
     "address" : {
         "street" : "Hoeger Mall",
         "suite" : "Apt. 692",
         "city" : "South Elvis",
         "zipcode" : "53919-4257",
         "geo" : { "lat" : "29.4572", "lng" : "-164.2990" }
     },
     "phone" : "493-170-9623 x156",
     "website" : "kale.biz",
     "company" : {
         "name" : "Robel-Corkery",
         "catchPhrase" :
             "Multi-tiered zero tolerance productivity",
         "bs" : "transition cutting-edge web services"
     }
 },
 {
     "id" : 5,
     "name" : "Chelsey Dietrich",
     "username" : "Kamren",
     "email" : "Lucio_Hettinger@annie.ca",
     "address" : {
         "street" : "Skiles Walks",
         "suite" : "Suite 351",
         "city" : "Roscoeview",
         "zipcode" : "33263",
         "geo" : { "lat" : "-31.8129", "lng" : "62.5342" }
     },
     "phone" : "(254)954-1289",
     "website" : "demarco.info",
     "company" : {
         "name" : "Keebler LLC",
         "catchPhrase" :
             "User-centric fault-tolerant solution",
         "bs" : "revolutionize end-to-end systems"
     }
 },
 {
     "id" : 6,
     "name" : "Mrs. Dennis Schulist",
     "username" : "Leopoldo_Corkery",
     "email" : "Karley_Dach@jasper.info",
     "address" : {
         "street" : "Norberto Crossing",
         "suite" : "Apt. 950",
         "city" : "South Christy",
         "zipcode" : "23505-1337",
         "geo" : { "lat" : "-71.4197", "lng" : "71.7478" }
     },
     "phone" : "1-477-935-8478 x6430",
     "website" : "ola.org",
     "company" : {
         "name" : "Considine-Lockman",
         "catchPhrase" :
             "Synchronised bottom-line interface",
         "bs" : "e-enable innovative applications"
     }
 },
 {
     "id" : 7,
     "name" : "Kurtis Weissnat",
     "username" : "Elwyn.Skiles",
     "email" : "Telly.Hoeger@billy.biz",
     "address" : {
         "street" : "Rex Trail",
         "suite" : "Suite 280",
         "city" : "Howemouth",
         "zipcode" : "58804-1099",
         "geo" : { "lat" : "24.8918", "lng" : "21.8984" }
     },
     "phone" : "210.067.6132",
     "website" : "elvis.io",
     "company" : {
         "name" : "Johns Group",
         "catchPhrase" :
             "Configurable multimedia task-force",
         "bs" : "generate enterprise e-tailers"
     }
 },
 {
     "id" : 8,
     "name" : "Nicholas Runolfsdottir V",
     "username" : "Maxime_Nienow",
     "email" : "Sherwood@rosamond.me",
     "address" : {
         "street" : "Ellsworth Summit",
         "suite" : "Suite 729",
         "city" : "Aliyaview",
         "zipcode" : "45169",
         "geo" : { "lat" : "-14.3990", "lng" : "-120.7677" }
     },
     "phone" : "586.493.6943 x140",
     "website" : "jacynthe.com",
     "company" : {
         "name" : "Abernathy Group",
         "catchPhrase" : "Implemented secondary concept",
         "bs" : "e-enable extensible e-tailers"
     }
 },
 {
     "id" : 9,
     "name" : "Glenna Reichert",
     "username" : "Delphine",
     "email" : "Chaim_McDermott@dana.io",
     "address" : {
         "street" : "Dayna Park",
         "suite" : "Suite 449",
         "city" : "Bartholomebury",
         "zipcode" : "76495-3109",
         "geo" : { "lat" : "24.6463", "lng" : "-168.8889" }
     },
     "phone" : "(775)976-6794 x41206",
     "website" : "conrad.com",
     "company" : {
         "name" : "Yost and Sons",
         "catchPhrase" :
             "Switchable contextually-based project",
         "bs" : "aggregate real-time technologies"
     }
 },
 {
     "id" : 10,
     "name" : "Clementina DuBuque",
     "username" : "Moriah.Stanton",
     "email" : "Rey.Padberg@karina.biz",
     "address" : {
         "street" : "Kattie Turnpike",
         "suite" : "Suite 198",
         "city" : "Lebsackbury",
         "zipcode" : "31428-2261",
         "geo" : { "lat" : "-38.2386", "lng" : "57.2232" }
     },
     "phone" : "024-648-3804",
     "website" : "ambrose.net",
     "company" : {
         "name" : "Hoeger LLC",
         "catchPhrase" :
             "Centralized empowering task-force",
         "bs" : "target end-to-end models"
     }
 }]

Step 4: Mock server configuration

Within the configuration tab, we are going to set the mock server name to mock users api. You can set it to your preffared name. next, select the Save the mock server URL as an environment variable checkbox. now that you have completed the configuration, click on the create mock server button on your bottom right. before proceeding to the next step, let us understand some important concept in the configuration.

  • Environment: Environments help manage variables like URLs or tokens.
  • Make mock server private: is used when you want to make your mock api secure by adding authentication
  • Simulate fixed network delay: this feature for testing how your application behaves under different network conditions. It allows you to identify potential issues related to network latency and ensure that your application handles delays appropriately.

WhatsApp-Image-2023-12-18-at-21132-AM

Step 5: Test mock request

Navigate to the collections tab on the left side of the navigation bar, then click on the mock server api collection which we created and select users.

WhatsApp-Image-2023-12-18-at-23455-AM

Next, click on the send button on the top right hand of your postman to see sample JSON request.
WhatsApp-Image-2023-12-18-at-24204-AM


Previous Article
Next Article

Similar Reads

Create and use mock servers for API testing or development in Postman
Postman, a comprehensive API platform, includes a robust API client for exploring, testing and defining requests. Its notable feature is the ability to create mock servers, simulating API responses for testing and development purposes. Developers can organize requests in collections, generate mock servers, and customize settings to mimic desired AP
4 min read
How to Create Load Balancing Servers using Node.js ?
In node, Load balancing is a technique used to distribute incoming network traffic across multiple servers to ensure no single server becomes overwhelmed, thus improving responsiveness and availability. In this article, we'll explore how to create a load-balancing server using Node.js. Why Load Balancing?Load balancing is essential for: Improved Pe
8 min read
How to create routes using Express and Postman?
In this article we are going to implement different HTTP routes using Express JS and Postman. Server side routes are different endpoints of a application that are used to exchange data from client side to server side. Express.js is a framework that works on top of Node.js server to simplify its APIs and add new features. It makes it easier to organ
3 min read
How do Web Servers work?
The Internet acts as a source of a plethora of information to us and all we need to do if we want any information is to just query the internet and then we will get the desired response. But who provides this information to us and how? All this is facilitated by what is called the Web Server. Along with it, there are browsers as applications we use
5 min read
Servers, streams and sockets in Node
Node.js Server Node.js is a javascript framework for writing Server-side applications. A Node.js server provides the mechanisms for connecting to a service and sending/receiving data. It achieves this through TCP or UDP connections. Developers can hence create their own server and test their app deployment. NodeJS comes with a simple HTTP server bu
5 min read
Different Servers in Node.js
Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and it’s not a programming language. Most of people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end services like API
8 min read
Express Returns Servers HTML Error Page Instead of res.json Error Message
When building APIs with Express.js, you might encounter a situation where instead of returning a JSON error message, your server returns an HTML error page. This can be frustrating, especially when your application relies on consistent JSON responses. In this article, we'll explore why this happens and how to ensure that Express.js returns a JSON e
4 min read
How to create a new request in Postman?
Postman is a development tool that is used for testing web APIs i.e. Application Programming Interfaces. It allows you to test the functionality of any application's APIs. Almost every developer uses Postman for testing purposes. We can create any type of HTTP request in it such as GET, POST, PUT, DELETE, PATCH, etc. PrerequisitesKnowledge of APIsK
2 min read
Create and Manage Request Collections in Postman
Postman is a popular tool worldwide for making API (Application Programming Interface) Requests to testing them, before releasing them to the public. CRUD (Create-Read-Update-Delete) REST (REpresentational State Transfer) APIs of a simple application to manage the basic data of users of a company will be created. Then, on the basis of similarity to
4 min read
How to create and use global variables in Postman?
Postman is an API(application programming interface) development tool that helps to build, test and modify APIs. It can make various types of HTTP requests(GET, POST, PUT, PATCH), save environments for later use, and convert the API to code for various languages(like JavaScript, and Python). In this article, we will learn How do you create and use
2 min read
How to create and send POST requests in Postman?
Postman is an API(application programming interface) development tool which helps to build, test and modify APIs. It can make various types of HTTP requests(GET, POST, PUT, PATCH), saving environments for later use, and convert save the API to code for various languages(like JavaScript, and Python). In this article, we will learn how you create and
2 min read
How to create and send GET requests in Postman?
Postman is an API(application programming interface) development tool which helps to build, test and modify APIs. It has the ability to make various types of HTTP requests(GET, POST, PUT, PATCH), saving environments for later use, converting the API to code for various languages(like JavaScript, Python). In this article, we will learn How do you cr
1 min read
How to create and write tests for API requests in Postman?
Postman is an API(utility programming interface) development device that enables to construct, take a look at and alter APIs. It could make numerous varieties of HTTP requests(GET, POST, PUT, PATCH), store environments for later use, and convert the API to code for various languages(like JavaScript, and Python). In this article, we will learn How t
3 min read
How to test file uploads in Postman using Express?
In web development, handling file uploads is a major requirement for various APIs. Postman is a powerful tool used for API testing, facilitates the process of testing file uploads. In this article we will see how we can test file upload with the help of Postman. Prerequisites:Node and NPM/Yarn installed.Knowledge of Node JS and Express JSUnderstand
3 min read
How to handle Basic Auth in Postman using Express.
Authentication plays an important role in web development and API testing by making sure that only authorized individuals can access sensitive information or perform specific actions. Postman is a tool used for API development and testing. It offers support for managing different authentication methods such as Basic Auth and OAuth. In this article,
6 min read
How to dynamically manage data using variables in Postman?
In this article, we will learn dynamic data management in Postman through the use of variables. Postman, a substantially used API trying out and improvement device, gives a sturdy framework for growing, organizing, and executing API requests. Variables, as key components of Postman's capability, permit customers to inject flexibility, reusability,
4 min read
How to make Automation Projects using Postman ?
In this article, we will be seeing how you can use postman to make automation projects. This article will also help many developers and Penetration testers instead of Burp suite. You can also call postman interceptor as the mini version of Brupsuite Interceptor. Postman is a cutting-edge Automation tool, which can be used for API testing, Automated
2 min read
How to Count Records in JSON array using JavaScript and Postman ?
In this article, we are going to explore how JavaScript and Postman are used to count the number of records returned in a JSON array. Send a Request: Send a request to fetch the JSON array from your API endpoint in Postman.Access JSON Response: In the Postman test scripts tab, you can access the JSON response body using the pm.response.json() metho
2 min read
How to add nested object to existing JSON using Postman ?
Postman has become a critical tool for developers around the world, particularly when dealing with JSON data. This article will guide you through the process of adding nested objects to an existing JSON using Postman, with a focus on the approaches and syntax involved. Table of Content Understanding JSON and Nested ObjectsThe Role of PostmanAdding
4 min read
How to test an API using Postman ?
API testing is a software testing type that tends to validate the application programming interfaces. As per Postman API, API testing is confirming that an API is working as expected. It sends requests to an API and monitors the responses to check its behavior to assess the functionality, reliability, performance, and security of an API. It is usua
5 min read
Manage API data and workflows using Postman JavaScript objects
Managing API data and workflows efficiently is very important for developers. Postman, a popular API development environment, provides powerful tools to streamline this process. One such tool is Postman JavaScript objects, which allow you to manipulate data and automate workflows effectively. In this article, we'll learn how to use Postman JavaScri
2 min read
How to Replicate Postman POST API Request using AJAX ?
In this project we'll mimic the action of submitting data using POST to a server from a web page. We replicate this process using AJAX (Asynchronous JavaScript and XML) directly in a web page, we're embedding similar functionality within our own interface. This involves setting up HTML elements like input fields and buttons to gather user input, us
4 min read
How do you run Postman collections using Newman CLI?
Postman is an API(application programming interface) development tool that helps to build, test and modify APIs.  In this tutorial, we will see how to run Postman collections using Newman CLI(Command Line Interface) Prerequisites:Node JS installed in your systemKnowledge about how APIs worksStep 1 : Checking of Node version Newman is built on Node.
2 min read
How to Set, View and Manipulate Cookies using 'Response.cookie()' and Postman ?
Cookies enable websites to store small pieces of information on a user's device. It helps enhance user experience and enable various functionalities. In this article, we'll explore a simple way to manipulate cookies using the 'Response.cookie()' function Prerequisite:Basics of NodejsBasics of ExpressjsOne should be able to make a basic express serv
2 min read
How to generate API documentation using Postman?
Postman is a popular API testing tool that is used to simplify the process of developing and testing APIs (Application Programming Interface). API acts as a bridge between two software applications which enables them to communicate and share data. In this article, you will learn how to generate API documentation using Postman. PrerequisitesUndersta
2 min read
How To Generate Reports Using Postman Tool ?
Postman is a widely used tool for API testing. It offers a user-friendly interface for sending various HTTP requests (GET, POST, PUT, DELETE). One of the best things that we can do in Postman is Generate reports effectively. In this article, we will explore the various approaches to generating reports using the Postman Tool. PrerequisitesUnderstand
3 min read
Explain the process of testing file downloads using Postman.
In web development, handling file downloads is a major requirement for various APIs. Postman is a powerful tool used for API testing and provides the process of testing file uploads. In this article, we will see how we can test file downloads with the help of Postman. Prerequisites:Node and NPM/Yarn installed.Knowledge of Node JS and Express JSUnde
3 min read
How to generate automated test reports using Postman ?
Postman is the API testing tool that helps to simplify the process of developing and testing APIs (Application Programming Interface). In this article, we will explore how to not only create environments but also generate automated test reports, enhancing efficiency and reliability in the API testing workflow. Prerequisites:Postman downloaded and I
2 min read
How to display Image in Postman using Express ?
Postman is a powerful tool for testing APIs, but when it comes to displaying images, it can be a little bit tricky. This article, the process of setting up an Express server to serve images and accessing them using Postman. Prerequisites:PostmanExpress JSSteps to display Image in Postman:Step 1: Image Preparation Place your image file (e.g., 'image
2 min read
How To Make A GET Request using Postman and Express JS
Postman is an API(application programming interface) development tool that helps to build, test and modify APIs.  In this tutorial, we will see how To Make A GET Request using Postman and Express JS PrerequisitesNode JSExpress JSPostmanTable of Content What is GET Request?Steps to make a GET Request using Postman and Express.jsWhat is GET Request?T
3 min read
three90RightbarBannerImg