Skip to content

Commit 22761ce

Browse files
committed
Add detail for gRPC/HTTP transcoding
- Define which fields are mapped to query parameters (and how) - Specify behavior (and limitations) for fields represented in both the body and the URI
1 parent 83c133c commit 22761ce

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

aip/general/0127.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ message CreateBookRequest {
6868
- RPCs **should** use the prescribed HTTP verb for custom methods, as
6969
discussed in [AIP-136][].
7070
- RPCs **should not** use `put` or `custom`.
71-
- The corresponding value represents the URI.
71+
- The corresponding value represents the path in the URI.
7272
- URIs **must** use the `{foo=bar/*}` syntax to represent a variable that
7373
should be populated in the request proto. When extracting a [resource
7474
name][aip-122], the variable **must** include the entire resource name, not
@@ -81,7 +81,8 @@ message CreateBookRequest {
8181
- The `body` key defines which single top-level field in the request will be
8282
sent as the HTTP body. If the body is `*`, then this indicates that the
8383
request object itself is the HTTP body. The request body is encoded as JSON
84-
as defined by protocol buffers' canonical [JSON encoding][].
84+
as defined by protocol buffers' canonical [JSON encoding][]. Fields encoded
85+
in the URI
8586
- RPCs **must not** define a `body` at all for RPCs that use the `GET` or
8687
`DELETE` HTTP verbs.
8788
- RPCs **must** use the prescribed `body` for Create ([AIP-133][]) and Update
@@ -92,6 +93,17 @@ message CreateBookRequest {
9293
- The `body` **must not** be a `repeated` field.
9394
- Fields **should not** use the `json_name` annotation to alter the field
9495
name in JSON, unless doing so for backwards-compatibility reasons.
96+
- In any given HTTP request, if a field is represented in both the body
97+
and the URI, the values **must** be identical. The server behavior when
98+
this constraint is violated is unspecified.
99+
- Eligible fields which are not represented in the URI path or the body are mapped
100+
to URI query parameters.
101+
- Only singular primitive, repeated primitive, and singular message type fields
102+
are eligible to be represented as query parameters.
103+
- Repeated primitive fields are represented as repeated query parameters,
104+
e.g. `...?param=A&param=B`.
105+
- For message type fields, each eligible leaf field is represented as a
106+
separate query parameter, e.g. `...?foo.a=A&foo.b=B&foo.c=C`.
95107

96108
**Note:** Bi-directional streaming RPCs should not include a `google.api.http`
97109
annotation at all. If feasible, the service **should** provide non-streaming
@@ -127,6 +139,8 @@ rpc CreateBook(CreateBookRequest) returns (Book) {
127139

128140
## Changelog
129141

142+
- **2022-07-21**: Added clarification around field duplication between the
143+
body and URI, and added query parameter mapping.
130144
- **2021-01-06**: Added clarification around `body` and nested fields.
131145
- **2019-09-23**: Added a statement about request body encoding, and guidance
132146
discouraging `json_name`.

0 commit comments

Comments
 (0)