http.proto 15 KB

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