• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 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 parameters 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 are passed via the HTTP
215//      request body.
216//    - All other fields are passed via the URL query parameters, and the
217//      parameter name is the field path in the request message. A repeated
218//      field can be represented as multiple query parameters under the same
219//      name.
220//  2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL query parameter, all fields
221//     are passed via URL path and HTTP request body.
222//  3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP request body, all
223//     fields are passed via URL path and URL query parameters.
224//
225// ### Path template syntax
226//
227//     Template = "/" Segments [ Verb ] ;
228//     Segments = Segment { "/" Segment } ;
229//     Segment  = "*" | "**" | LITERAL | Variable ;
230//     Variable = "{" FieldPath [ "=" Segments ] "}" ;
231//     FieldPath = IDENT { "." IDENT } ;
232//     Verb     = ":" LITERAL ;
233//
234// The syntax `*` matches a single URL path segment. The syntax `**` matches
235// zero or more URL path segments, which must be the last part of the URL path
236// except the `Verb`.
237//
238// The syntax `Variable` matches part of the URL path as specified by its
239// template. A variable template must not contain other variables. If a variable
240// matches a single path segment, its template may be omitted, e.g. `{var}`
241// is equivalent to `{var=*}`.
242//
243// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL`
244// contains any reserved character, such characters should be percent-encoded
245// before the matching.
246//
247// If a variable contains exactly one path segment, such as `"{var}"` or
248// `"{var=*}"`, when such a variable is expanded into a URL path on the client
249// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The
250// server side does the reverse decoding. Such variables show up in the
251// [Discovery
252// Document](https://developers.google.com/discovery/v1/reference/apis) as
253// `{var}`.
254//
255// If a variable contains multiple path segments, such as `"{var=foo/*}"`
256// or `"{var=**}"`, when such a variable is expanded into a URL path on the
257// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded.
258// The server side does the reverse decoding, except "%2F" and "%2f" are left
259// unchanged. Such variables show up in the
260// [Discovery
261// Document](https://developers.google.com/discovery/v1/reference/apis) as
262// `{+var}`.
263//
264// ## Using gRPC API Service Configuration
265//
266// gRPC API Service Configuration (service config) is a configuration language
267// for configuring a gRPC service to become a user-facing product. The
268// service config is simply the YAML representation of the `google.api.Service`
269// proto message.
270//
271// As an alternative to annotating your proto file, you can configure gRPC
272// transcoding in your service config YAML files. You do this by specifying a
273// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same
274// effect as the proto annotation. This can be particularly useful if you
275// have a proto that is reused in multiple services. Note that any transcoding
276// specified in the service config will override any matching transcoding
277// configuration in the proto.
278//
279// Example:
280//
281//     http:
282//       rules:
283//         # Selects a gRPC method and applies HttpRule to it.
284//         - selector: example.v1.Messaging.GetMessage
285//           get: /v1/messages/{message_id}/{sub.subfield}
286//
287// ## Special notes
288//
289// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the
290// proto to JSON conversion must follow the [proto3
291// specification](https://developers.google.com/protocol-buffers/docs/proto3#json).
292//
293// While the single segment variable follows the semantics of
294// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String
295// Expansion, the multi segment variable **does not** follow RFC 6570 Section
296// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion
297// does not expand special characters like `?` and `#`, which would lead
298// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding
299// for multi segment variables.
300//
301// The path variables **must not** refer to any repeated or mapped field,
302// because client libraries are not capable of handling such variable expansion.
303//
304// The path variables **must not** capture the leading "/" character. The reason
305// is that the most common use case "{var}" does not capture the leading "/"
306// character. For consistency, all path variables must share the same behavior.
307//
308// Repeated message fields must not be mapped to URL query parameters, because
309// no client library can support such complicated mapping.
310//
311// If an API needs to use a JSON array for request or response body, it can map
312// the request or response body to a repeated field. However, some gRPC
313// Transcoding implementations may not support this feature.
314message HttpRule {
315  // Selects a method to which this rule applies.
316  //
317  // Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
318  string selector = 1;
319
320  // Determines the URL pattern is matched by this rules. This pattern can be
321  // used with any of the {get|put|post|delete|patch} methods. A custom method
322  // can be defined using the 'custom' field.
323  oneof pattern {
324    // Maps to HTTP GET. Used for listing and getting information about
325    // resources.
326    string get = 2;
327
328    // Maps to HTTP PUT. Used for replacing a resource.
329    string put = 3;
330
331    // Maps to HTTP POST. Used for creating a resource or performing an action.
332    string post = 4;
333
334    // Maps to HTTP DELETE. Used for deleting a resource.
335    string delete = 5;
336
337    // Maps to HTTP PATCH. Used for updating a resource.
338    string patch = 6;
339
340    // The custom pattern is used for specifying an HTTP method that is not
341    // included in the `pattern` field, such as HEAD, or "*" to leave the
342    // HTTP method unspecified for this rule. The wild-card rule is useful
343    // for services that provide content to Web (HTML) clients.
344    CustomHttpPattern custom = 8;
345  }
346
347  // The name of the request field whose value is mapped to the HTTP request
348  // body, or `*` for mapping all request fields not captured by the path
349  // pattern to the HTTP body, or omitted for not having any HTTP request body.
350  //
351  // NOTE: the referred field must be present at the top-level of the request
352  // message type.
353  string body = 7;
354
355  // Optional. The name of the response field whose value is mapped to the HTTP
356  // response body. When omitted, the entire response message will be used
357  // as the HTTP response body.
358  //
359  // NOTE: The referred field must be present at the top-level of the response
360  // message type.
361  string response_body = 12;
362
363  // Additional HTTP bindings for the selector. Nested bindings must
364  // not contain an `additional_bindings` field themselves (that is,
365  // the nesting may only be one level deep).
366  repeated HttpRule additional_bindings = 11;
367}
368
369// A custom pattern is used for defining custom HTTP verb.
370message CustomHttpPattern {
371  // The name of this custom HTTP verb.
372  string kind = 1;
373
374  // The path matched by this custom verb.
375  string path = 2;
376}
377