Using Postman to Mock APIs

If you don’t build mock APIs very often the best way to start mocking an API in Postman is to do the tutorial and then modify the samples.

There is a Bootcamp link in the bottom Right footer of the Postman app – mocking an API is currently the first lesson offered.

Postman Mock
Postman Mock

By the way, if you want to experiment with using custom error codes, this is a good way to try it out. There is a range of numbers between 452 and 499 are generally free to use for your own custom error codes.

After setting up the mock example, I quit Postman and refreshed the web page to verify that I can still access the mock without it running. I was able to. I am not sure if this is a good feature or not. There are cases when access to a mock API from a cloud host might be convenient, but I don’t know how long it remains. Some good authentication should be used to prevent unauthorized access, since the URL is discoverable.

I would be more comfortable if I had the option to host locally or on the cloud.

As I write this I have posted a question about mock host longevity on the Postman Community site. I noticed that a mock I created in early June 2022 was still running almost a month later. I was able to find it in my Mock Servers list and delete it, and it no longer sends the 200 response I had set it up with. Instead I get this:

{
    "error": {
        "name": "mockNotFoundError",
        "header": "Unable to find mock",
        "message": "Please refresh and try again."
    }
}

I will leave the other mock I set up running. Try it!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha loading...

This site uses Akismet to reduce spam. Learn how your comment data is processed.