http.proto 15 KB

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