http.proto 8.5 KB

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