一篇带给你Postman gRPC功能使用介绍

本文介绍了Postman支持gRPC的历程,从v9.7.1的初步支持到v9.14.0的改进,详细说明了如何在Postman中设置gRPC服务URL、选择服务方法、调用接口以及定义消息结构体。还提到Postman在导入本地文件时的限制,并分享了使用体验的提升。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对于API调试工具来说近几年国内有不少整合的比较好的工具,比如Apifox、Apipost等。这些工具主打主打功能整合,多种功能集成一步到位,但目前对于协议的多样性则支持得较慢,截止本文写作时间点,其更多类型的支持暂时放到了后续规划中。

Postman

  Postman作为API调试的老大哥,整体的功能时比较全的,WebSocket(也是BETA)之前就已经支持了。而在最近的几个版本中Postman也提供了gRPC功能的支持。截止本文时间点,Postman最新版本为v9.14.0,所以本文也是基于该版本进行学习和功能使用介绍。

  Release Notes

  Postman在最近几个版本中对grpc的功能进行了beta测试。

  Postman v9.7.1

  在v9.7.1中Postman首次支持了gRPC功能的使用,在当时版本中已经基本支持了gRPC的单独功能使用。主要支持了单次、单双向流式的gRPC调用。同时也能使用Postman中的变量。

 在这个版本中需要我们手动在Postman中定义Proto文件。

 

  Postman v9.9.0

  在v9.9.0中支持了直接加载服务器中暴露出来的gRPC方法来直接使用。

 

Postman v9.14.0

  在v9.14.0中可以直接使用加载本地中的proto文件作为定义文件来使用。

  使用流程

  在Postman中的接口定义流程和v9.7.1中基本一致,通过新建Request以及选择gRPC来建立一个gRPC。其中主要定义功能我分为了6块,具体分割如下图:

service URL

  需要定义service URL地址,ip或域名,主要注意是要指定gRPC的接口。

  服务方法组

  比较重要的是服务方法的选择。目前有四种添加途径:

  1. 通过服务器扫描映射

  2. 加载本地文件

  3. 通过URL加载定义文件

  4. 直接创建一个新的API定义

但需要注意,通过服务器映射的这个方法我自己实际测试并不能完全地扫描到所有的服务器接口,可能是有用法上的问题。

  而导入本地文件、使用导入url以及直接定义新的链接本质上都是在Postman的APIs管理中添加了一个Protobuf定义文件,所以在v9.14.0版本的更新中所添加的“本地文件导入功能”,仅仅是帮助用户省去了在APIs中新建定义接口的功能,但是直接将用户的功能使用路线全部聚焦到接口调试界面中,我认为很大程度的提高了用户使用体验。

 

但是不一样的是,在使用本地导入的时候,如果使用"import"关键字引入了其他的proto定义文件,postman暂时无法描述这种定义关系,在request中可以直接使用,但是无法保存,也无法记录到APIs中。所以尽量按照规范将接口描述在一个proto文件中。

  调用方法

  选择需要调用的具体方法,其中左侧图标会标记出方法的调用类型。

  消息定义

  消息定义区域中有有三个tab,message中使用JSON方式来定义消息结构体,在使用JSON定义结构体的时候字符串与数值类型会自动在发送的时候根据proto中定义的类型。其余两个的使用方式与Http API基本一致。

  便捷工具

  目前提供了“美化”与“请求样例生成”功能,值得注意的是,在早期版本中样例生成是用""的图标,但是在目前版本中直接使用文字进行提示了,我猜测是因为灯泡的图标在大众的使用习惯中主要是“帮助”、“提示”的意思,所有导致该功能的使用率较低,所以直接换成了文字进行提示。

  响应体

  该部分以JSON格式展示返回信息,以及其他的响应状态与访问时间等。

最后

  因为实际的使用需求所以对该Postman工具中的gRPC部分进行了使用上的学习。根据Release Notes以及git上的Issues观察了软件的演进这件事还挺有意思的。

 

 

 

Postman is a popular API development tool that allows developers to create, test, and share APIs in a user-friendly interface. While Postman primarily supports REST APIs, it also supports gRPC APIs. gRPC is a high-performance, open-source framework that enables efficient communication between services using remote procedure calls (RPCs). It uses Protocol Buffers (protobuf) to define service contracts and data types, and supports a wide range of programming languages. To use Postman with gRPC, you'll need to do the following steps: 1. Install the Postman gRPC plugin: You can install the Postman gRPC plugin from the Postman app store. Once you've installed the plugin, you'll be able to create gRPC requests in Postman. 2. Define the gRPC service: Use the gRPC proto file to define the service and messages. The proto file contains the service definition and the data types used in the service. You can import the proto file into Postman and use it to create requests. 3. Create a new gRPC request: In Postman, create a new request and select the gRPC tab. Enter the service URL and select the method you want to call. You can then enter the request parameters and send the request. 4. View the response: Once you've sent the request, you can view the response in the Postman UI. The response will be displayed in a structured format based on the data types defined in the proto file. Postman also supports gRPC streaming, which allows you to make bidirectional streaming requests between a client and a server. You can use the streaming feature to send and receive large data sets or continuous data streams. Overall, using Postman with gRPC can help you streamline your API development and testing process, and make it easier to create and test high-performance APIs.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值