<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Appurva Murawat</title>
    <description>The latest articles on DEV Community by Appurva Murawat (@appurva21).</description>
    <link>https://dev.to/appurva21</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F907171%2F2df8dc00-c5c4-48af-8a66-b9308ee3432e.jpeg</url>
      <title>DEV Community: Appurva Murawat</title>
      <link>https://dev.to/appurva21</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/appurva21"/>
    <language>en</language>
    <item>
      <title>Testing gRPC APIs with Postman</title>
      <dc:creator>Appurva Murawat</dc:creator>
      <pubDate>Thu, 11 Aug 2022 03:07:11 +0000</pubDate>
      <link>https://dev.to/postman/testing-grpc-apis-with-postman-3d6d</link>
      <guid>https://dev.to/postman/testing-grpc-apis-with-postman-3d6d</guid>
      <description>&lt;p&gt;This article was written by &lt;a href="https://blog.postman.com/author/appurva-murawat/" rel="noopener noreferrer"&gt;Appurva Murawat&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Testing an API ensures that it consistently delivers the necessary functionality, performance, reliability, and security you need. It gives you the confidence to develop and ship faster, speeding up discoverability by API consumers. But it can be tedious, inefficient, and, more importantly, unreliable to manually test each time you add a new feature or fix a bug in your APIs. That’s what we’ve worked to solve for &lt;a href="https://blog.postman.com/postman-now-supports-grpc/" rel="noopener noreferrer"&gt;Postman’s gRPC support.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Postman announced first-class support for gRPC at the beginning of this year and followed it up with &lt;a href="https://blog.postman.com/latest-advancements-to-postmans-grpc-support/" rel="noopener noreferrer"&gt;loads of improvements&lt;/a&gt; based on some truly fantastic feedback we received from our gRPC community on &lt;a href="https://github.com/postmanlabs/postman-app-support/issues?q=is%3Aissue+label%3Agrpc+is%3Aopen" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. And now, with the latest release, we’ve supercharged our gRPC support by adding the capability of writing test specifications for all your use cases. We hope these improvements will make your workflow even more efficient by allowing easier development and testing of your APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  New yet familiar
&lt;/h2&gt;

&lt;p&gt;Postman strives to provide the most straightforward and powerful user interfaces so that you can focus on the actual task without thinking too hard about navigating new territory. We bring this philosophy to the new gRPC testing interface as well. If you have ever used Postman to debug and &lt;a href="https://learning.postman.com/docs/writing-scripts/test-scripts/" rel="noopener noreferrer"&gt;write tests for your REST APIs&lt;/a&gt;, guess what, those are the same concepts you need to know for writing tests for your gRPC requests in Postman. If you’re a newcomer, don’t worry about it, we’ve got you covered: check out the &lt;a href="https://learning.postman.com/labs/postman-api-client/grpc-client/writing-scripts/scripting-in-grpc-request/" rel="noopener noreferrer"&gt;Postman Learning Center&lt;/a&gt; to get started.&lt;/p&gt;

&lt;p&gt;To add a test, open your gRPC request and switch to the  &lt;strong&gt;Scripts&lt;/strong&gt;  tab. You can use Postman’s robust Javascript-based scripting environment to author test suites. You can add two different scripts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Before invoke&lt;/strong&gt; : executes before invoking the method and establishing a connection with the server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After response&lt;/strong&gt; : executes once the current transaction is complete (i.e., connection with the server is closed)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Fnavigating-to-grpc-scripts.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Fnavigating-to-grpc-scripts.gif" alt="Navigating to scripts in the gRPC request"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Navigating to scripts in the gRPC request&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once you’ve written the tests (more on that in a moment), you can observe the test assertions summary beside your response(s) under the &lt;strong&gt;Test results&lt;/strong&gt;  tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Finvoke-grpc-request-with-tests.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Finvoke-grpc-request-with-tests.gif" alt="Invoking a gRPC request with tests"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Invoking a gRPC request with tests&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Get off the blocks in no time
&lt;/h2&gt;

&lt;p&gt;Let’s start by writing our first test, so you can quickly see things in action:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to the  &lt;strong&gt;After&lt;/strong&gt;  &lt;strong&gt;response&lt;/strong&gt; script of your gRPC request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From the list of  &lt;strong&gt;Snippets ** on the right, choose **Status code is 0.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click  &lt;strong&gt;Invoke.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There you have it, your first test!&lt;/p&gt;

&lt;p&gt;Both before invoke and after response scripts come with pre-curated lists of commonly used code &lt;a href="https://learning.postman.com/labs/postman-api-client/grpc-client/writing-scripts/writing-tests/#using-snippets" rel="noopener noreferrer"&gt;snippets&lt;/a&gt; that get added to your scripts when selected, helping you start quickly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Fusing-snippets-in-grpc-scripts-1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Fusing-snippets-in-grpc-scripts-1.gif" alt="Authoring after response script using a snippet"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Authoring after response script using a snippet&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Speed and accuracy superpower
&lt;/h2&gt;

&lt;p&gt;Snippets are excellent for primary use cases, but as you can imagine, there might be more complex and custom scenarios that you want to test. For that, you can use the complete range of &lt;a href="https://learning.postman.com/labs/postman-api-client/grpc-client/writing-scripts/postman-sandbox-api/" rel="noopener noreferrer"&gt;pm.* APIs&lt;/a&gt; to craft your scripts. Check out the below tests to get a taste of all the things that you can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm.test('Response time is below 200ms', function () { 
  pm.response.to.have.responseTime.below(200); 
});

pm.test('Correct user details are recevied', function () {
  pm.response.to.have.message({ id: "123", name: "John" });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can even validate the messages against a given JSON schema, allowing you to enforce a number of custom rules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const schema = { 
  type: "object", 
  properties: { 
    name: { 
      type: "string", 
      pattern: "^[a-zA-Z0-9_]*$", 
      maxLength: 64 
    } 
  }, 
  required: ['name'] 
}; 

pm.test('All response messages have valid name', function () { 
  pm.response.messages.to.have.jsonSchema(schema); 
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As engineers, we understand that it might not always be efficient for you to refer to the documentation—that’s where the autocompletion for Javascript and the pm.* APIs in our script editor comes in, empowering you with all the information you need to author your scripts swiftly and accurately. Hopefully, this saves you some trips to Stack Overflow as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Fautocompletion-in-grpc-scripts.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.postman.com%2Fwp-content%2Fuploads%2F2022%2F08%2Fautocompletion-in-grpc-scripts.gif" alt="Autocompletion in gRPC scripts"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Autocompletion in action&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Leave nothing to chance
&lt;/h2&gt;

&lt;p&gt;All the features and workflows mentioned above extend to unary, client streaming, server streaming, and bidirectional streaming gRPC methods alike. This makes it easier to have test specifications for all your gRPC APIs in a single place—Postman!&lt;/p&gt;

&lt;h2&gt;
  
  
  More to come
&lt;/h2&gt;

&lt;p&gt;The ability to test your gRPC APIs is a powerful addition to the &lt;a href="https://blog.postman.com/new-postman-api-platform-redefining-api-management-for-api-first-world/" rel="noopener noreferrer"&gt;Postman API Platform&lt;/a&gt;, and it’s another way we’re working to help users throughout the &lt;a href="https://dev.to/jansche/the-8-point-api-lifecycle-blueprint-3op4-temp-slug-9748578"&gt;API lifecycle&lt;/a&gt;. And gRPC support continues to evolve. Keep an eye out for more upcoming releases, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Saving examples for gRPC request&lt;/li&gt;
&lt;li&gt;Automatic mock servers for all imported Protobuf APIs&lt;/li&gt;
&lt;li&gt;Automating your gRPC testing workflows using Postman’s &lt;a href="https://learning.postman.com/docs/running-collections/intro-to-collection-runs/" rel="noopener noreferrer"&gt;Collection Runner&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://blog.postman.com/testing-grpc-apis-with-postman/" rel="noopener noreferrer"&gt;Testing gRPC APIs with Postman&lt;/a&gt; was written by Appurva Murawat and appeared first on &lt;a href="https://blog.postman.com" rel="noopener noreferrer"&gt;Postman Blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>api</category>
      <category>postman</category>
      <category>testing</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
