blob: 673adc0611ca9fd6fcb5763475767ec95b7966ac [file] [log] [blame]
David K. Bainbridge24ff0232019-04-30 13:26:19 -07001// Copyright 2018 Google LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15
16syntax = "proto3";
17
18package google.api;
19
20option cc_enable_arenas = true;
21option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
22option java_multiple_files = true;
23option java_outer_classname = "HttpProto";
24option java_package = "com.google.api";
25option objc_class_prefix = "GAPI";
26
27// Defines the HTTP configuration for an API service. It contains a list of
28// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method
29// to one or more HTTP REST API methods.
30message Http {
31 // A list of HTTP configuration rules that apply to individual API methods.
32 //
33 // **NOTE:** All service configuration rules follow "last one wins" order.
34 repeated HttpRule rules = 1;
35
36 // When set to true, URL path parmeters will be fully URI-decoded except in
37 // cases of single segment matches in reserved expansion, where "%2F" will be
38 // left encoded.
39 //
40 // The default behavior is to not decode RFC 6570 reserved characters in multi
41 // segment matches.
42 bool fully_decode_reserved_expansion = 2;
43}
44
45// # gRPC Transcoding
46//
47// gRPC Transcoding is a feature for mapping between a gRPC method and one or
48// more HTTP REST endpoints. It allows developers to build a single API service
49// that supports both gRPC APIs and REST APIs. Many systems, including [Google
50// APIs](https://github.com/googleapis/googleapis),
51// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC
52// Gateway](https://github.com/grpc-ecosystem/grpc-gateway),
53// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature
54// and use it for large scale production services.
55//
56// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies
57// how different portions of the gRPC request message are mapped to the URL
58// path, URL query parameters, and HTTP request body. It also controls how the
59// gRPC response message is mapped to the HTTP response body. `HttpRule` is
60// typically specified as an `google.api.http` annotation on the gRPC method.
61//
62// Each mapping specifies a URL path template and an HTTP method. The path
63// template may refer to one or more fields in the gRPC request message, as long
64// as each field is a non-repeated field with a primitive (non-message) type.
65// The path template controls how fields of the request message are mapped to
66// the URL path.
67//
68// Example:
69//
70// service Messaging {
71// rpc GetMessage(GetMessageRequest) returns (Message) {
72// option (google.api.http) = {
73// get: "/v1/{name=messages/*}"
74// };
75// }
76// }
77// message GetMessageRequest {
78// string name = 1; // Mapped to URL path.
79// }
80// message Message {
81// string text = 1; // The resource content.
82// }
83//
84// This enables an HTTP REST to gRPC mapping as below:
85//
86// HTTP | gRPC
87// -----|-----
88// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")`
89//
90// Any fields in the request message which are not bound by the path template
91// automatically become HTTP query parameters if there is no HTTP request body.
92// For example:
93//
94// service Messaging {
95// rpc GetMessage(GetMessageRequest) returns (Message) {
96// option (google.api.http) = {
97// get:"/v1/messages/{message_id}"
98// };
99// }
100// }
101// message GetMessageRequest {
102// message SubMessage {
103// string subfield = 1;
104// }
105// string message_id = 1; // Mapped to URL path.
106// int64 revision = 2; // Mapped to URL query parameter `revision`.
107// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`.
108// }
109//
110// This enables a HTTP JSON to RPC mapping as below:
111//
112// HTTP | gRPC
113// -----|-----
114// `GET /v1/messages/123456?revision=2&sub.subfield=foo` |
115// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield:
116// "foo"))`
117//
118// Note that fields which are mapped to URL query parameters must have a
119// primitive type or a repeated primitive type or a non-repeated message type.
120// In the case of a repeated type, the parameter can be repeated in the URL
121// as `...?param=A&param=B`. In the case of a message type, each field of the
122// message is mapped to a separate parameter, such as
123// `...?foo.a=A&foo.b=B&foo.c=C`.
124//
125// For HTTP methods that allow a request body, the `body` field
126// specifies the mapping. Consider a REST update method on the
127// message resource collection:
128//
129// service Messaging {
130// rpc UpdateMessage(UpdateMessageRequest) returns (Message) {
131// option (google.api.http) = {
132// patch: "/v1/messages/{message_id}"
133// body: "message"
134// };
135// }
136// }
137// message UpdateMessageRequest {
138// string message_id = 1; // mapped to the URL
139// Message message = 2; // mapped to the body
140// }
141//
142// The following HTTP JSON to RPC mapping is enabled, where the
143// representation of the JSON in the request body is determined by
144// protos JSON encoding:
145//
146// HTTP | gRPC
147// -----|-----
148// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id:
149// "123456" message { text: "Hi!" })`
150//
151// The special name `*` can be used in the body mapping to define that
152// every field not bound by the path template should be mapped to the
153// request body. This enables the following alternative definition of
154// the update method:
155//
156// service Messaging {
157// rpc UpdateMessage(Message) returns (Message) {
158// option (google.api.http) = {
159// patch: "/v1/messages/{message_id}"
160// body: "*"
161// };
162// }
163// }
164// message Message {
165// string message_id = 1;
166// string text = 2;
167// }
168//
169//
170// The following HTTP JSON to RPC mapping is enabled:
171//
172// HTTP | gRPC
173// -----|-----
174// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id:
175// "123456" text: "Hi!")`
176//
177// Note that when using `*` in the body mapping, it is not possible to
178// have HTTP parameters, as all fields not bound by the path end in
179// the body. This makes this option more rarely used in practice when
180// defining REST APIs. The common usage of `*` is in custom methods
181// which don't use the URL at all for transferring data.
182//
183// It is possible to define multiple HTTP methods for one RPC by using
184// the `additional_bindings` option. Example:
185//
186// service Messaging {
187// rpc GetMessage(GetMessageRequest) returns (Message) {
188// option (google.api.http) = {
189// get: "/v1/messages/{message_id}"
190// additional_bindings {
191// get: "/v1/users/{user_id}/messages/{message_id}"
192// }
193// };
194// }
195// }
196// message GetMessageRequest {
197// string message_id = 1;
198// string user_id = 2;
199// }
200//
201// This enables the following two alternative HTTP JSON to RPC mappings:
202//
203// HTTP | gRPC
204// -----|-----
205// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
206// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id:
207// "123456")`
208//
209// ## Rules for HTTP mapping
210//
211// 1. Leaf request fields (recursive expansion nested messages in the request
212// message) are classified into three categories:
213// - Fields referred by the path template. They are passed via the URL path.
214// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They
215// are passed via the HTTP
216// request body.
217// - All other fields are passed via the URL query parameters, and the
218// parameter name is the field path in the request message. A repeated
219// field can be represented as multiple query parameters under the same
220// name.
221// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL
222// query parameter, all fields
223// are passed via URL path and HTTP request body.
224// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP
225// request body, all
226// fields are passed via URL path and URL query parameters.
227//
228// ### Path template syntax
229//
230// Template = "/" Segments [ Verb ] ;
231// Segments = Segment { "/" Segment } ;
232// Segment = "*" | "**" | LITERAL | Variable ;
233// Variable = "{" FieldPath [ "=" Segments ] "}" ;
234// FieldPath = IDENT { "." IDENT } ;
235// Verb = ":" LITERAL ;
236//
237// The syntax `*` matches a single URL path segment. The syntax `**` matches
238// zero or more URL path segments, which must be the last part of the URL path
239// except the `Verb`.
240//
241// The syntax `Variable` matches part of the URL path as specified by its
242// template. A variable template must not contain other variables. If a variable
243// matches a single path segment, its template may be omitted, e.g. `{var}`
244// is equivalent to `{var=*}`.
245//
246// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL`
247// contains any reserved character, such characters should be percent-encoded
248// before the matching.
249//
250// If a variable contains exactly one path segment, such as `"{var}"` or
251// `"{var=*}"`, when such a variable is expanded into a URL path on the client
252// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The
253// server side does the reverse decoding. Such variables show up in the
254// [Discovery
255// Document](https://developers.google.com/discovery/v1/reference/apis) as
256// `{var}`.
257//
258// If a variable contains multiple path segments, such as `"{var=foo/*}"`
259// or `"{var=**}"`, when such a variable is expanded into a URL path on the
260// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded.
261// The server side does the reverse decoding, except "%2F" and "%2f" are left
262// unchanged. Such variables show up in the
263// [Discovery
264// Document](https://developers.google.com/discovery/v1/reference/apis) as
265// `{+var}`.
266//
267// ## Using gRPC API Service Configuration
268//
269// gRPC API Service Configuration (service config) is a configuration language
270// for configuring a gRPC service to become a user-facing product. The
271// service config is simply the YAML representation of the `google.api.Service`
272// proto message.
273//
274// As an alternative to annotating your proto file, you can configure gRPC
275// transcoding in your service config YAML files. You do this by specifying a
276// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same
277// effect as the proto annotation. This can be particularly useful if you
278// have a proto that is reused in multiple services. Note that any transcoding
279// specified in the service config will override any matching transcoding
280// configuration in the proto.
281//
282// Example:
283//
284// http:
285// rules:
286// # Selects a gRPC method and applies HttpRule to it.
287// - selector: example.v1.Messaging.GetMessage
288// get: /v1/messages/{message_id}/{sub.subfield}
289//
290// ## Special notes
291//
292// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the
293// proto to JSON conversion must follow the [proto3
294// specification](https://developers.google.com/protocol-buffers/docs/proto3#json).
295//
296// While the single segment variable follows the semantics of
297// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String
298// Expansion, the multi segment variable **does not** follow RFC 6570 Section
299// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion
300// does not expand special characters like `?` and `#`, which would lead
301// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding
302// for multi segment variables.
303//
304// The path variables **must not** refer to any repeated or mapped field,
305// because client libraries are not capable of handling such variable expansion.
306//
307// The path variables **must not** capture the leading "/" character. The reason
308// is that the most common use case "{var}" does not capture the leading "/"
309// character. For consistency, all path variables must share the same behavior.
310//
311// Repeated message fields must not be mapped to URL query parameters, because
312// no client library can support such complicated mapping.
313//
314// If an API needs to use a JSON array for request or response body, it can map
315// the request or response body to a repeated field. However, some gRPC
316// Transcoding implementations may not support this feature.
317message HttpRule {
318 // Selects a method to which this rule applies.
319 //
320 // Refer to [selector][google.api.DocumentationRule.selector] for syntax
321 // details.
322 string selector = 1;
323
324 // Determines the URL pattern is matched by this rules. This pattern can be
325 // used with any of the {get|put|post|delete|patch} methods. A custom method
326 // can be defined using the 'custom' field.
327 oneof pattern {
328 // Maps to HTTP GET. Used for listing and getting information about
329 // resources.
330 string get = 2;
331
332 // Maps to HTTP PUT. Used for replacing a resource.
333 string put = 3;
334
335 // Maps to HTTP POST. Used for creating a resource or performing an action.
336 string post = 4;
337
338 // Maps to HTTP DELETE. Used for deleting a resource.
339 string delete = 5;
340
341 // Maps to HTTP PATCH. Used for updating a resource.
342 string patch = 6;
343
344 // The custom pattern is used for specifying an HTTP method that is not
345 // included in the `pattern` field, such as HEAD, or "*" to leave the
346 // HTTP method unspecified for this rule. The wild-card rule is useful
347 // for services that provide content to Web (HTML) clients.
348 CustomHttpPattern custom = 8;
349 }
350
351 // The name of the request field whose value is mapped to the HTTP request
352 // body, or `*` for mapping all request fields not captured by the path
353 // pattern to the HTTP body, or omitted for not having any HTTP request body.
354 //
355 // NOTE: the referred field must be present at the top-level of the request
356 // message type.
357 string body = 7;
358
359 // Optional. The name of the response field whose value is mapped to the HTTP
360 // response body. When omitted, the entire response message will be used
361 // as the HTTP response body.
362 //
363 // NOTE: The referred field must be present at the top-level of the response
364 // message type.
365 string response_body = 12;
366
367 // Additional HTTP bindings for the selector. Nested bindings must
368 // not contain an `additional_bindings` field themselves (that is,
369 // the nesting may only be one level deep).
370 repeated HttpRule additional_bindings = 11;
371}
372
373// A custom pattern is used for defining custom HTTP verb.
374message CustomHttpPattern {
375 // The name of this custom HTTP verb.
376 string kind = 1;
377
378 // The path matched by this custom verb.
379 string path = 2;
380}