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
To try it out, all you need is a working Go 1.6 development environment and the following simple commands:
78
78
79
79
```sh
80
-
$ go get -u github.com/philips/grpc-gateway-example
81
-
$ grpc-gateway-example serve
80
+
go get -u github.com/philips/grpc-gateway-example
81
+
grpc-gateway-example serve
82
82
```
83
83
84
84
With the server running you can try requests on both HTTP 1.1 and gRPC interfaces:
85
85
86
86
```sh
87
-
$ grpc-gateway-example echo Take a REST from REST with gRPC
88
-
$ curl -X POST -k https://localhost:10000/v1/echo -d '{"value": "CoreOS is hiring!"}'
87
+
grpc-gateway-example echo Take a REST from REST with gRPC
88
+
curl -X POST -k https://localhost:10000/v1/echo -d '{"value": "CoreOS is hiring!"}'
89
89
```
90
90
91
91
One last bonus: because we have an Open API specification, you can browse the Open API UI running at `https://localhost:10000/swagger-ui/#!/EchoService/Echo` if you have the server above running on your laptop.
Copy file name to clipboardExpand all lines: content/en/blog/grpc-with-json.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -172,17 +172,17 @@ final class KvService extends KvGson.KeyValueServiceImplBase {
172
172
After implementing all the methods on the server, we now have a fully functioning gRPC Java, JSON encoding RPC system. And to show you there is nothing up my sleeve:
173
173
174
174
```sh
175
-
$ ./gradlew :dependencies | grep -i proto
176
-
$ # no proto deps!
175
+
./gradlew :dependencies | grep -i proto
176
+
# no proto deps!
177
177
```
178
178
179
179
## Optimizing the Code
180
180
181
181
WhileGson is not as fast as Protobuf, there's no sense in not picking the low hanging fruit. Running the code we see the performance is pretty slow:
182
182
183
183
```sh
184
-
$ ./gradlew installDist
185
-
$ time ./build/install/kvstore/bin/kvstore
184
+
./gradlew installDist
185
+
time ./build/install/kvstore/bin/kvstore
186
186
187
187
INFO: Did 215.883 RPCs/s
188
188
```
@@ -213,8 +213,8 @@ That's not right! Looking at a `RetrieveRequest`, we see that the key bytes are
213
213
Using this in our marshallers, we can see a dramatic performance difference:
0 commit comments