http.proto 15 KB

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