Postman Now Has Mocking Magic for gRPC

Avatar

Here at Postman, we love gRPC. It’s a fast and reliable protocol with tons of indispensable features. But most importantly, it was designed to be API-first. If you’ve been reading our blog posts, you’ll know by now that we’re kind of obsessed with this “API-first” thing—and for good reason! That’s because it allows us to get our jobs done at lightning speed. Do you want to get stuff done at lightning speed? Yes? Well then hop on the gRPC bandwagon, and allow me to show you what’s possible with the Postman API Platform.

Decouple your teams

Let’s consider a fairly common situation: you’re building a new feature that depends on some new API endpoints, but another team is responsible for building those endpoints. Oftentimes, your team might be completely blocked until the other team finishes their part of the development. Or perhaps, to avoid that, they’re tasked with generating fixtures for you, but in reality, they never deliver the fixtures on time.

Luckily, you’re using Postman! So as soon as the new endpoints have been designed and added to your Protobuf API, you already have a mock server implementing those endpoints. That’s right, you didn’t need to create a mock server—it’s just there. Simply choose Use Mock Server from the server URL drop-down to start using a mock server.

Using a mock server with a gRPC request
Using a mock server with a gRPC request

Test with confidence

Let’s consider another common situation: you’re writing tests, but your application depends on a few external services that are managed by other teams in your organization. Testing against the real services would DDoS your own company. Testing against the beta instances would cause your tests to be flakey and unreliable. The better option is to create mock versions of those services—but then you have to update your mocks whenever the real services change. Your manually handwritten mocks will never stay up-to-date against the endless stream of changes being done in real life; they’ll just deteriorate over time.

Luckily, with Postman you can just copy and paste the mock URL of their Protobuf API, and you have instant, reliable mocking that always stays up-to-date as their service changes. To write tests, you probably need to get the same response every time, but that’s easy because Postman’s gRPC mock servers are powered by a seeded, deterministic random number generator. Just pass a seed in the request, and enjoy the same data every time.

To find and pass a seed, all you need to do is go to the Metadata section of the response, copy the seed value, and then create a new key/value pair in the Message Metadata section. It’s that simple!

Persist seed data across invocations
Persist seed data across invocations

When we introduced these automatic mock servers internally at Postman, some people said they feel like magic. But we hope you use them to the point that they become the most common tool in your arsenal—common like a package manager: you can’t imagine how you ever lived without them.

What’s next?

If you’re not using gRPC yet, don’t worry: Postman’s automatic mock servers will be coming to other protocols soon. Also, scenario-based mocking is on the horizon for situations when you need more control over your mock data. Those of you who are waiting for feature-parity with Postman’s HTTP offerings won’t be waiting much longer.

Watch and learn

Try Postman now

 

What do you think about this feature? Tell us in a comment below. You can also give product feedback through our Community forum and GitHub repository.

Comment

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


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