http.proto 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. // Copyright 2016 Google Inc.
  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 java_multiple_files = true;
  18. option java_outer_classname = "HttpProto";
  19. option java_package = "com.google.api";
  20. option objc_class_prefix = "GAPI";
  21. // Defines the HTTP configuration for a service. It contains a list of
  22. // [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method
  23. // to one or more HTTP REST API methods.
  24. message Http {
  25. // A list of HTTP configuration rules that apply to individual API methods.
  26. //
  27. // **NOTE:** All service configuration rules follow "last one wins" order.
  28. repeated HttpRule rules = 1;
  29. }
  30. // `HttpRule` defines the mapping of an RPC method to one or more HTTP
  31. // REST APIs. The mapping determines what portions of the request
  32. // message are populated from the path, query parameters, or body of
  33. // the HTTP request. The mapping is typically specified as an
  34. // `google.api.http` annotation, see "google/api/annotations.proto"
  35. // for details.
  36. //
  37. // The mapping consists of a field specifying the path template and
  38. // method kind. The path template can refer to fields in the request
  39. // message, as in the example below which describes a REST GET
  40. // operation on a resource collection of messages:
  41. //
  42. // ```proto
  43. // service Messaging {
  44. // rpc GetMessage(GetMessageRequest) returns (Message) {
  45. // option (google.api.http).get = "/v1/messages/{message_id}/{sub.subfield}";
  46. // }
  47. // }
  48. // message GetMessageRequest {
  49. // message SubMessage {
  50. // string subfield = 1;
  51. // }
  52. // string message_id = 1; // mapped to the URL
  53. // SubMessage sub = 2; // `sub.subfield` is url-mapped
  54. // }
  55. // message Message {
  56. // string text = 1; // content of the resource
  57. // }
  58. // ```
  59. //
  60. // This definition enables an automatic, bidrectional mapping of HTTP
  61. // JSON to RPC. Example:
  62. //
  63. // HTTP | RPC
  64. // -----|-----
  65. // `GET /v1/messages/123456/foo` | `GetMessage(message_id: "123456" sub: SubMessage(subfield: "foo"))`
  66. //
  67. // In general, not only fields but also field paths can be referenced
  68. // from a path pattern. Fields mapped to the path pattern cannot be
  69. // repeated and must have a primitive (non-message) type.
  70. //
  71. // Any fields in the request message which are not bound by the path
  72. // pattern automatically become (optional) HTTP query
  73. // parameters. Assume the following definition of the request message:
  74. //
  75. // ```proto
  76. // message GetMessageRequest {
  77. // message SubMessage {
  78. // string subfield = 1;
  79. // }
  80. // string message_id = 1; // mapped to the URL
  81. // int64 revision = 2; // becomes a parameter
  82. // SubMessage sub = 3; // `sub.subfield` becomes a parameter
  83. // }
  84. // ```
  85. //
  86. // This enables a HTTP JSON to RPC mapping as below:
  87. //
  88. // HTTP | RPC
  89. // -----|-----
  90. // `GET /v1/messages/123456?revision=2&sub.subfield=foo` | `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: "foo"))`
  91. //
  92. // Note that fields which are mapped to HTTP parameters must have a
  93. // primitive type or a repeated primitive type. Message types are not
  94. // allowed. In the case of a repeated type, the parameter can be
  95. // repeated in the URL, as in `...?param=A&param=B`.
  96. //
  97. // For HTTP method kinds which allow a request body, the `body` field
  98. // specifies the mapping. Consider a REST update method on the
  99. // message resource collection:
  100. //
  101. // ```proto
  102. // service Messaging {
  103. // rpc UpdateMessage(UpdateMessageRequest) returns (Message) {
  104. // option (google.api.http) = {
  105. // put: "/v1/messages/{message_id}"
  106. // body: "message"
  107. // };
  108. // }
  109. // }
  110. // message UpdateMessageRequest {
  111. // string message_id = 1; // mapped to the URL
  112. // Message message = 2; // mapped to the body
  113. // }
  114. // ```
  115. //
  116. // The following HTTP JSON to RPC mapping is enabled, where the
  117. // representation of the JSON in the request body is determined by
  118. // protos JSON encoding:
  119. //
  120. // HTTP | RPC
  121. // -----|-----
  122. // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" message { text: "Hi!" })`
  123. //
  124. // The special name `*` can be used in the body mapping to define that
  125. // every field not bound by the path template should be mapped to the
  126. // request body. This enables the following alternative definition of
  127. // the update method:
  128. //
  129. // ```proto
  130. // service Messaging {
  131. // rpc UpdateMessage(Message) returns (Message) {
  132. // option (google.api.http) = {
  133. // put: "/v1/messages/{message_id}"
  134. // body: "*"
  135. // };
  136. // }
  137. // }
  138. // message Message {
  139. // string message_id = 1;
  140. // string text = 2;
  141. // }
  142. // ```
  143. //
  144. // The following HTTP JSON to RPC mapping is enabled:
  145. //
  146. // HTTP | RPC
  147. // -----|-----
  148. // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")`
  149. //
  150. // Note that when using `*` in the body mapping, it is not possible to
  151. // have HTTP parameters, as all fields not bound by the path end in
  152. // the body. This makes this option more rarely used in practice of
  153. // defining REST APIs. The common usage of `*` is in custom methods
  154. // which don't use the URL at all for transferring data.
  155. //
  156. // It is possible to define multiple HTTP methods for one RPC by using
  157. // the `additional_bindings` option. Example:
  158. //
  159. // ```proto
  160. // service Messaging {
  161. // rpc GetMessage(GetMessageRequest) returns (Message) {
  162. // option (google.api.http) = {
  163. // get: "/v1/messages/{message_id}"
  164. // additional_bindings {
  165. // get: "/v1/users/{user_id}/messages/{message_id}"
  166. // }
  167. // };
  168. // }
  169. // }
  170. // message GetMessageRequest {
  171. // string message_id = 1;
  172. // string user_id = 2;
  173. // }
  174. // ```
  175. //
  176. // This enables the following two alternative HTTP JSON to RPC
  177. // mappings:
  178. //
  179. // HTTP | RPC
  180. // -----|-----
  181. // `GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
  182. // `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")`
  183. //
  184. // # Rules for HTTP mapping
  185. //
  186. // The rules for mapping HTTP path, query parameters, and body fields
  187. // to the request message are as follows:
  188. //
  189. // 1. The `body` field specifies either `*` or a field path, or is
  190. // omitted. If omitted, it assumes there is no HTTP body.
  191. // 2. Leaf fields (recursive expansion of nested messages in the
  192. // request) can be classified into three types:
  193. // (a) Matched in the URL template.
  194. // (b) Covered by body (if body is `*`, everything except (a) fields;
  195. // else everything under the body field)
  196. // (c) All other fields.
  197. // 3. URL query parameters found in the HTTP request are mapped to (c) fields.
  198. // 4. Any body sent with an HTTP request can contain only (b) fields.
  199. //
  200. // The syntax of the path template is as follows:
  201. //
  202. // Template = "/" Segments [ Verb ] ;
  203. // Segments = Segment { "/" Segment } ;
  204. // Segment = "*" | "**" | LITERAL | Variable ;
  205. // Variable = "{" FieldPath [ "=" Segments ] "}" ;
  206. // FieldPath = IDENT { "." IDENT } ;
  207. // Verb = ":" LITERAL ;
  208. //
  209. // The syntax `*` matches a single path segment. It follows the semantics of
  210. // [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String
  211. // Expansion.
  212. //
  213. // The syntax `**` matches zero or more path segments. It follows the semantics
  214. // of [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.3 Reserved
  215. // Expansion.
  216. //
  217. // The syntax `LITERAL` matches literal text in the URL path.
  218. //
  219. // The syntax `Variable` matches the entire path as specified by its template;
  220. // this nested template must not contain further variables. If a variable
  221. // matches a single path segment, its template may be omitted, e.g. `{var}`
  222. // is equivalent to `{var=*}`.
  223. //
  224. // NOTE: the field paths in variables and in the `body` must not refer to
  225. // repeated fields or map fields.
  226. //
  227. // Use CustomHttpPattern to specify any HTTP method that is not included in the
  228. // `pattern` field, such as HEAD, or "*" to leave the HTTP method unspecified for
  229. // a given URL path rule. The wild-card rule is useful for services that provide
  230. // content to Web (HTML) clients.
  231. message HttpRule {
  232. // Selects methods to which this rule applies.
  233. //
  234. // Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
  235. string selector = 1;
  236. // Determines the URL pattern is matched by this rules. This pattern can be
  237. // used with any of the {get|put|post|delete|patch} methods. A custom method
  238. // can be defined using the 'custom' field.
  239. oneof pattern {
  240. // Used for listing and getting information about resources.
  241. string get = 2;
  242. // Used for updating a resource.
  243. string put = 3;
  244. // Used for creating a resource.
  245. string post = 4;
  246. // Used for deleting a resource.
  247. string delete = 5;
  248. // Used for updating a resource.
  249. string patch = 6;
  250. // Custom pattern is used for defining custom verbs.
  251. CustomHttpPattern custom = 8;
  252. }
  253. // The name of the request field whose value is mapped to the HTTP body, or
  254. // `*` for mapping all fields not captured by the path pattern to the HTTP
  255. // body. NOTE: the referred field must not be a repeated field and must be
  256. // present at the top-level of response message type.
  257. string body = 7;
  258. // Additional HTTP bindings for the selector. Nested bindings must
  259. // not contain an `additional_bindings` field themselves (that is,
  260. // the nesting may only be one level deep).
  261. repeated HttpRule additional_bindings = 11;
  262. }
  263. // A custom pattern is used for defining custom HTTP verb.
  264. message CustomHttpPattern {
  265. // The name of this custom HTTP verb.
  266. string kind = 1;
  267. // The path matched by this custom verb.
  268. string path = 2;
  269. }