You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/grpc/test-tools.md
+36-23Lines changed: 36 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,26 @@
1
1
---
2
-
title: Test services with gRPC tools
2
+
title: Test gRPC services with gRPCurl in ASP.NET Core
3
3
author: jamesnk
4
4
description: Learn how to test services with gRPC tools. gRPCurl a command-line tool for interacting with gRPC services. gRPCui is an interactive web UI.
By [James Newton-King](https://twitter.com/jamesnk)
14
14
15
-
Tooling is available for gRPC that allows developers to test services without building client apps. [gRPCurl](https://github.com/fullstorydev/grpcurl) is a command-line tool that provides interaction with gRPC services. [gRPCui](https://github.com/fullstorydev/grpcui) adds an interactive web UI for gRPC.
15
+
Tooling is available for gRPC that allows developers to test services without building client apps:
16
+
17
+
*[gRPCurl](https://github.com/fullstorydev/grpcurl) is a command-line tool that provides interaction with gRPC services.
18
+
*[gRPCui](https://github.com/fullstorydev/grpcui) builds on top of gRPCurl and adds an interactive web UI for gRPC, similar to tools such as Postman and Swagger UI.
16
19
17
20
This article discusses how to:
18
21
19
22
* Download and install gRPCurl and gRPCui.
20
-
*Setup gRPC reflection with a gRPC ASP.NET Core app.
23
+
*Set up gRPC reflection with a gRPC ASP.NET Core app.
21
24
* Discover and test gRPC services with `grpcurl`.
22
25
* Interact with gRPC services via a browser using `grpcui`.
23
26
@@ -32,21 +35,31 @@ gRPCurl is a command-line tool created by the gRPC community. Its features inclu
32
35
33
36
For information about downloading and installing `grpcurl`, see the [gRPCurl GitHub homepage](https://github.com/fullstorydev/grpcurl#installation).
`grpcurl` must know the Protobuf contract of services before it can call them. There are two ways to do this:
36
43
37
-
`grpcurl` needs to know the Protobuf contract of services before it can call them. There are two ways to do this:
44
+
* Set up [gRPC reflection](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) on the server. gRPCurl automatically discovers service contracts.
45
+
* Specify `.proto` files in command-line arguments to gRPCurl.
38
46
39
-
* Use gRPC reflection to discover service contracts.
40
-
* Specify *.proto* files in command-line arguments.
47
+
It's easier to use gRPCurl with gRPC reflection. gRPC reflection adds a new gRPC service to the app that clients can call to discover services.
41
48
42
-
It's easier to use gRPCurl with gRPC reflection and service discovery. gRPC ASP.NET Core has built-in support for gRPC reflection with the [Grpc.AspNetCore.Server.Reflection](https://www.nuget.org/packages/Grpc.AspNetCore.Server.Reflection) package. To configure reflection in an app:
49
+
gRPC ASP.NET Core has built-in support for gRPC reflection with the [`Grpc.AspNetCore.Server.Reflection`](https://www.nuget.org/packages/Grpc.AspNetCore.Server.Reflection) package. To configure reflection in an app:
43
50
44
-
* Add `Grpc.AspNetCore.Server.Reflection` package reference.
45
-
* Register reflection in *Startup.cs*:
51
+
* Add a `Grpc.AspNetCore.Server.Reflection` package reference.
52
+
* Register reflection in `Startup.cs`:
46
53
*`AddGrpcReflection` to register services that enable reflection.
47
-
*`MapGrpcReflectionService` to add reflection service endpoint.
54
+
*`MapGrpcReflectionService` to add a reflection service endpoint.
* A gRPC reflection service is added to the server app.
61
+
* Client apps that support gRPC reflection can call the reflection service to discover services hosted by the server.
62
+
* gRPC services are still called from the client. Reflection only enables service discovery and doesn't bypass server-side security. Endpoints protected by [authentication and authorization](xref:grpc/authn-and-authz) require the caller to pass credentials for the endpoint to be called successfully.
50
63
51
64
## Use `grpcurl`
52
65
@@ -75,12 +88,12 @@ service ServerReflection {
75
88
76
89
The preceding example:
77
90
78
-
* Runs `describe` verb on server `localhost:5001`.
91
+
* Runs the `describe` verb on server `localhost:5001`.
79
92
* Prints services and methods returned by gRPC reflection.
80
93
*`Greeter` is a service implemented by the app.
81
94
*`ServerReflection` is the service added by the `Grpc.AspNetCore.Server.Reflection` package.
82
95
83
-
Combine `describe` with a service, method or message name to view its detail:
96
+
Combine `describe` with a service, method, or message name to view its detail:
Call a gRPC service by specifying a service and method name, along with a JSON argument that represents the request message. The JSON is converted into Protobuf and sent to the service.
108
+
Call a gRPC service by specifying a service and method name along with a JSON argument that represents the request message. The JSON is converted into Protobuf and sent to the service.
@@ -101,33 +114,33 @@ Call a gRPC service by specifying a service and method name, along with a JSON a
101
114
}
102
115
```
103
116
104
-
The preceding example:
117
+
In the preceding example:
105
118
106
-
*`-d` argument specifies a request message with JSON. This argument must come before the server address and method name.
119
+
*The `-d` argument specifies a request message with JSON. This argument must come before the server address and method name.
107
120
* Calls the `SayHello` method on the `greeter.Greeter` service.
108
121
* Prints the response message as JSON.
109
122
110
123
## About gRPCui
111
124
112
-
gRPCui is an interactive web UI for gRPC. It builds on top of gRPCurl, and offers a GUI for discovering and testing gRPC services, similar to HTTP tools like Postman.
125
+
gRPCui is an interactive web UI for gRPC. It builds on top of gRPCurl and offers a GUI for discovering and testing gRPC services, similar to HTTP tools such as Postman or Swagger UI.
113
126
114
127
For information about downloading and installing `grpcui`, see the [gRPCui GitHub homepage](https://github.com/fullstorydev/grpcui#installation).
115
128
116
129
## Using `grpcui`
117
130
118
-
Run `grpcui` with the server address to interact with as an argument.
131
+
Run `grpcui` with the server address to interact with as an argument:
119
132
120
133
```powershell
121
134
> grpcui.exe localhost:5001
122
135
gRPC Web UI available at http://127.0.0.1:55038/
123
136
```
124
137
125
-
The tool will launch a browser window with the interactive web UI. gRPC services are automatically discovered using gRPC reflection.
138
+
The tool launches a browser window with the interactive web UI. gRPC services are automatically discovered using gRPC reflection.
126
139
127
140

0 commit comments