http.proto 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // 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. 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 parmeters 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. // `HttpRule` defines the mapping of an RPC method to one or more HTTP
  39. // REST API methods. The mapping specifies how different portions of the RPC
  40. // request message are mapped to URL path, URL query parameters, and
  41. // HTTP request body. The mapping is typically specified as an
  42. // `google.api.http` annotation on the RPC method,
  43. // see "google/api/annotations.proto" for details.
  44. //
  45. // The mapping consists of a field specifying the path template and
  46. // method kind. The path template can refer to fields in the request
  47. // message, as in the example below which describes a REST GET
  48. // operation on a resource collection of messages:
  49. //
  50. //
  51. // service Messaging {
  52. // rpc GetMessage(GetMessageRequest) returns (Message) {
  53. // option (google.api.http).get = "/v1/messages/{message_id}/{sub.subfield}";
  54. // }
  55. // }
  56. // message GetMessageRequest {
  57. // message SubMessage {
  58. // string subfield = 1;
  59. // }
  60. // string message_id = 1; // mapped to the URL
  61. // SubMessage sub = 2; // `sub.subfield` is url-mapped
  62. // }
  63. // message Message {
  64. // string text = 1; // content of the resource
  65. // }
  66. //
  67. // The same http annotation can alternatively be expressed inside the
  68. // `GRPC API Configuration` YAML file.
  69. //
  70. // http:
  71. // rules:
  72. // - selector: <proto_package_name>.Messaging.GetMessage
  73. // get: /v1/messages/{message_id}/{sub.subfield}
  74. //
  75. // This definition enables an automatic, bidrectional mapping of HTTP
  76. // JSON to RPC. Example:
  77. //
  78. // HTTP | RPC
  79. // -----|-----
  80. // `GET /v1/messages/123456/foo` | `GetMessage(message_id: "123456" sub: SubMessage(subfield: "foo"))`
  81. //
  82. // In general, not only fields but also field paths can be referenced
  83. // from a path pattern. Fields mapped to the path pattern cannot be
  84. // repeated and must have a primitive (non-message) type.
  85. //
  86. // Any fields in the request message which are not bound by the path
  87. // pattern automatically become (optional) HTTP query
  88. // parameters. Assume the following definition of the request message:
  89. //
  90. //
  91. // service Messaging {
  92. // rpc GetMessage(GetMessageRequest) returns (Message) {
  93. // option (google.api.http).get = "/v1/messages/{message_id}";
  94. // }
  95. // }
  96. // message GetMessageRequest {
  97. // message SubMessage {
  98. // string subfield = 1;
  99. // }
  100. // string message_id = 1; // mapped to the URL
  101. // int64 revision = 2; // becomes a parameter
  102. // SubMessage sub = 3; // `sub.subfield` becomes a parameter
  103. // }
  104. //
  105. //
  106. // This enables a HTTP JSON to RPC mapping as below:
  107. //
  108. // HTTP | RPC
  109. // -----|-----
  110. // `GET /v1/messages/123456?revision=2&sub.subfield=foo` | `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: "foo"))`
  111. //
  112. // Note that fields which are mapped to HTTP parameters must have a
  113. // primitive type or a repeated primitive type. Message types are not
  114. // allowed. In the case of a repeated type, the parameter can be
  115. // repeated in the URL, as in `...?param=A&param=B`.
  116. //
  117. // For HTTP method kinds which allow a request body, the `body` field
  118. // specifies the mapping. Consider a REST update method on the
  119. // message resource collection:
  120. //
  121. //
  122. // service Messaging {
  123. // rpc UpdateMessage(UpdateMessageRequest) returns (Message) {
  124. // option (google.api.http) = {
  125. // put: "/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. //
  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 | RPC
  141. // -----|-----
  142. // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "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. // put: "/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 | RPC
  166. // -----|-----
  167. // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")`
  168. //
  169. // Note that when using `*` in the body mapping, it is not possible to
  170. // have HTTP parameters, as all fields not bound by the path end in
  171. // the body. This makes this option more rarely used in practice of
  172. // defining REST APIs. The common usage of `*` is in custom methods
  173. // which don't use the URL at all for transferring data.
  174. //
  175. // It is possible to define multiple HTTP methods for one RPC by using
  176. // the `additional_bindings` option. Example:
  177. //
  178. // service Messaging {
  179. // rpc GetMessage(GetMessageRequest) returns (Message) {
  180. // option (google.api.http) = {
  181. // get: "/v1/messages/{message_id}"
  182. // additional_bindings {
  183. // get: "/v1/users/{user_id}/messages/{message_id}"
  184. // }
  185. // };
  186. // }
  187. // }
  188. // message GetMessageRequest {
  189. // string message_id = 1;
  190. // string user_id = 2;
  191. // }
  192. //
  193. //
  194. // This enables the following two alternative HTTP JSON to RPC
  195. // mappings:
  196. //
  197. // HTTP | RPC
  198. // -----|-----
  199. // `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
  200. // `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")`
  201. //
  202. // # Rules for HTTP mapping
  203. //
  204. // The rules for mapping HTTP path, query parameters, and body fields
  205. // to the request message are as follows:
  206. //
  207. // 1. The `body` field specifies either `*` or a field path, or is
  208. // omitted. If omitted, it indicates there is no HTTP request body.
  209. // 2. Leaf fields (recursive expansion of nested messages in the
  210. // request) can be classified into three types:
  211. // (a) Matched in the URL template.
  212. // (b) Covered by body (if body is `*`, everything except (a) fields;
  213. // else everything under the body field)
  214. // (c) All other fields.
  215. // 3. URL query parameters found in the HTTP request are mapped to (c) fields.
  216. // 4. Any body sent with an HTTP request can contain only (b) fields.
  217. //
  218. // The syntax of the path template is as follows:
  219. //
  220. // Template = "/" Segments [ Verb ] ;
  221. // Segments = Segment { "/" Segment } ;
  222. // Segment = "*" | "**" | LITERAL | Variable ;
  223. // Variable = "{" FieldPath [ "=" Segments ] "}" ;
  224. // FieldPath = IDENT { "." IDENT } ;
  225. // Verb = ":" LITERAL ;
  226. //
  227. // The syntax `*` matches a single path segment. The syntax `**` matches zero
  228. // or more path segments, which must be the last part of the path except the
  229. // `Verb`. The syntax `LITERAL` matches literal text in the path.
  230. //
  231. // The syntax `Variable` matches part of the URL path as specified by its
  232. // template. A variable template must not contain other variables. If a variable
  233. // matches a single path segment, its template may be omitted, e.g. `{var}`
  234. // is equivalent to `{var=*}`.
  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, all characters
  238. // except `[-_.~0-9a-zA-Z]` are percent-encoded. Such variables show up in the
  239. // Discovery Document as `{var}`.
  240. //
  241. // If a variable contains one or more path segments, such as `"{var=foo/*}"`
  242. // or `"{var=**}"`, when such a variable is expanded into a URL path, all
  243. // characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. Such variables
  244. // show up in the Discovery Document as `{+var}`.
  245. //
  246. // NOTE: While the single segment variable matches the semantics of
  247. // [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2
  248. // Simple String Expansion, the multi segment variable **does not** match
  249. // RFC 6570 Reserved Expansion. The reason is that the Reserved Expansion
  250. // does not expand special characters like `?` and `#`, which would lead
  251. // to invalid URLs.
  252. //
  253. // NOTE: the field paths in variables and in the `body` must not refer to
  254. // repeated fields or map fields.
  255. message HttpRule {
  256. // Selects methods to which this rule applies.
  257. //
  258. // Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
  259. string selector = 1;
  260. // Determines the URL pattern is matched by this rules. This pattern can be
  261. // used with any of the {get|put|post|delete|patch} methods. A custom method
  262. // can be defined using the 'custom' field.
  263. oneof pattern {
  264. // Used for listing and getting information about resources.
  265. string get = 2;
  266. // Used for updating a resource.
  267. string put = 3;
  268. // Used for creating a resource.
  269. string post = 4;
  270. // Used for deleting a resource.
  271. string delete = 5;
  272. // Used for updating a resource.
  273. string patch = 6;
  274. // The custom pattern is used for specifying an HTTP method that is not
  275. // included in the `pattern` field, such as HEAD, or "*" to leave the
  276. // HTTP method unspecified for this rule. The wild-card rule is useful
  277. // for services that provide content to Web (HTML) clients.
  278. CustomHttpPattern custom = 8;
  279. }
  280. // The name of the request field whose value is mapped to the HTTP body, or
  281. // `*` for mapping all fields not captured by the path pattern to the HTTP
  282. // body. NOTE: the referred field must not be a repeated field and must be
  283. // present at the top-level of request message type.
  284. string body = 7;
  285. // Optional. The name of the response field whose value is mapped to the HTTP
  286. // body of response. Other response fields are ignored. When
  287. // not set, the response message will be used as HTTP body of response.
  288. string response_body = 12;
  289. // Additional HTTP bindings for the selector. Nested bindings must
  290. // not contain an `additional_bindings` field themselves (that is,
  291. // the nesting may only be one level deep).
  292. repeated HttpRule additional_bindings = 11;
  293. }
  294. // A custom pattern is used for defining custom HTTP verb.
  295. message CustomHttpPattern {
  296. // The name of this custom HTTP verb.
  297. string kind = 1;
  298. // The path matched by this custom verb.
  299. string path = 2;
  300. }