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
You may need to authenticate with GitHub to pull `docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env`.
43
43
You can do this by following the steps on the [GitHub Package docs](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages#authenticating-to-github-packages).
44
44
45
-
####Using Visual Studio Code dev containers
45
+
### Using Visual Studio Code dev containers
46
46
47
47
This repo contains a `devcontainer.json` configuration that sets up the build environment in a container using
48
48
[VS Code dev containers](https://code.visualstudio.com/docs/remote/containers). If you're using the dev container,
More examples are available under `examples` directory.
351
+
More examples are available under the `examples` directory.
348
352
349
353
-`proto/examplepb/echo_service.proto`, `proto/examplepb/a_bit_of_everything.proto`, `proto/examplepb/unannotated_echo_service.proto`: service definition
350
354
-`proto/examplepb/echo_service.pb.go`, `proto/examplepb/a_bit_of_everything.pb.go`, `proto/examplepb/unannotated_echo_service.pb.go`: [generated] stub of the service
@@ -365,7 +369,7 @@ gRPC-gateway, and a gRPC server, see
365
369
- Generating JSON API handlers.
366
370
- Method parameters in the request body.
367
371
- Method parameters in the request path.
368
-
- Method parameters in query string.
372
+
- Method parameters in the query string.
369
373
- Enum fields in the path parameter (including repeated enum fields).
370
374
- Mapping streaming APIs to newline-delimited JSON streams.
371
375
- Mapping HTTP headers with `Grpc-Metadata-` prefix to gRPC metadata (prefixed with `grpcgateway-`)
@@ -381,14 +385,14 @@ gRPC-gateway, and a gRPC server, see
381
385
382
386
### No plan to support
383
387
384
-
But patch is welcome.
388
+
But patches are welcome.
385
389
386
390
- Method parameters in HTTP headers.
387
391
- Handling trailer metadata.
388
392
- Encoding request/response body in XML.
389
393
- True bi-directional streaming.
390
394
391
-
# Mapping gRPC to HTTP
395
+
##Mapping gRPC to HTTP
392
396
393
397
-[How gRPC error codes map to HTTP status codes in the response](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/errors.go#L15).
394
398
- HTTP request source IP is added as `X-Forwarded-For` gRPC request header.
@@ -404,11 +408,11 @@ But patch is welcome.
404
408
[jsonpb](https://pkg.go.dev/github.com/golang/protobuf/jsonpb) with
405
409
`OrigName: true`.
406
410
407
-
# Contribution
411
+
##Contribution
408
412
409
413
See [CONTRIBUTING.md](http://github.com/grpc-ecosystem/grpc-gateway/blob/master/CONTRIBUTING.md).
410
414
411
-
# License
415
+
##License
412
416
413
-
grpc-gateway is licensed under the BSD 3-Clause License.
417
+
gRPC-Gateway is licensed under the BSD 3-Clause License.
414
418
See [LICENSE.txt](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/LICENSE.txt) for more details.
Copy file name to clipboardExpand all lines: docs/docs/tutorials/adding_annotations.md
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
---
2
2
layout: default
3
-
title: Adding the grpc-gateway annotations to an existing protobuf file
3
+
title: Adding gRPC-Gateway annotations to an existing proto file
4
+
nav_order: 4
4
5
parent: Tutorials
5
-
nav_order: 5
6
6
---
7
7
8
-
# Adding the grpc-gateway annotations to an existing protobuf file
8
+
# Adding gRPC-Gateway annotations to an existing proto file
9
9
10
-
Now that we've got a working Go gRPC server, we need to add the grpc-gateway annotations.
10
+
Now that we've got a working Go gRPC server, we need to add the gRPC-Gateway annotations.
11
11
12
12
The annotations define how gRPC services map to the JSON request and response. When using protocol buffers, each RPC must define the HTTP method and path using the `google.api.http` annotation.
13
13
14
-
So we will need to add the `google/api/http.proto` import to the proto file. We also need to add the HTTP->gRPC mapping we want. In this case, we're mapping `POST /v1/example/echo` to our `SayHello`rpc.
14
+
So we will need to add the `google/api/http.proto` import to the proto file. We also need to add the HTTP->gRPC mapping we want. In this case, we're mapping `POST /v1/example/echo` to our `SayHello`RPC.
15
15
16
-
```proto
16
+
```protobuf
17
17
syntax = "proto3";
18
18
19
19
package helloworld;
@@ -44,11 +44,11 @@ message HelloReply {
44
44
45
45
See [a_bit_of_everything.proto](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/internal/proto/examplepb/a_bit_of_everything.proto) for examples of more annotations you can add to customize gateway behavior.
46
46
47
-
## Generating the grpc-gateway stubs
47
+
## Generating the gRPC-Gateway stubs
48
48
49
-
Now that we've got the grpc-gateway annotations added to the proto file, we need to use the grpc-gateway generator to generate the stubs.
49
+
Now that we've got the gRPC-Gateway annotations added to the proto file, we need to use the gRPC-Gateway generator to generate the stubs.
50
50
51
-
Before we can do that, we need to copy some dependencies into our protofile structure. Copy the `third_party/googleapis` folder from the grpc-gateway repository to your local protofile structure. It should look like this afterwards:
51
+
Before we can do that, we need to copy some dependencies into our proto file structure. Copy the `third_party/googleapis` folder from the gRPC-Gateway repository to your local proto file structure. It should look like this afterwards:
52
52
53
53
```
54
54
proto
@@ -62,9 +62,9 @@ proto
62
62
63
63
### Using buf
64
64
65
-
We'll need to add the grpc-gateway generator to the generation configuration:
65
+
We'll need to add the gRPC-Gateway generator to the generation configuration:
66
66
67
-
```yml
67
+
```yaml
68
68
version: v1beta1
69
69
plugins:
70
70
- name: go
@@ -86,9 +86,9 @@ $ buf generate
86
86
87
87
It should produce a `*.gw.pb.go` file.
88
88
89
-
### Using protoc
89
+
### Using `protoc`
90
90
91
-
Now we need to add the grpc-gateway generator to the protoc invocation:
91
+
Now we need to add the gRPC-Gateway generator to the `protoc` invocation:
92
92
93
93
```sh
94
94
$ protoc -I ./proto \
@@ -100,7 +100,7 @@ $ protoc -I ./proto \
100
100
101
101
This should generate a `*.gw.pb.go` file.
102
102
103
-
We also need to add and serve the gRPC-gateway mux in our `main.go` file.
103
+
We also need to add and serve the gRPC-Gateway mux in our `main.go` file.
0 commit comments