http_bookstore.proto 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Copyright 2016 Google Inc. All Rights Reserved.
  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. //
  15. ////////////////////////////////////////////////////////////////////////////////
  16. syntax = "proto3";
  17. package endpoints.examples.bookstore;
  18. option java_multiple_files = true;
  19. option java_outer_classname = "BookstoreProto";
  20. option java_package = "com.google.endpoints.examples.bookstore";
  21. import "google/api/annotations.proto";
  22. import "google/protobuf/empty.proto";
  23. // A simple Bookstore API.
  24. //
  25. // The API manages shelves and books resources. Shelves contain books.
  26. service Bookstore {
  27. // Returns a list of all shelves in the bookstore.
  28. rpc ListShelves(google.protobuf.Empty) returns (ListShelvesResponse) {
  29. // Define HTTP mapping.
  30. // Client example (Assuming your service is hosted at the given 'DOMAIN_NAME'):
  31. // curl http://DOMAIN_NAME/v1/shelves
  32. option (google.api.http) = { get: "/v1/shelves" };
  33. }
  34. // Creates a new shelf in the bookstore.
  35. rpc CreateShelf(CreateShelfRequest) returns (Shelf) {
  36. // Client example:
  37. // curl -d '{"theme":"Music"}' http://DOMAIN_NAME/v1/shelves
  38. option (google.api.http) = {
  39. post: "/v1/shelves"
  40. body: "shelf"
  41. };
  42. }
  43. // Returns a specific bookstore shelf.
  44. rpc GetShelf(GetShelfRequest) returns (Shelf) {
  45. // Client example - returns the first shelf:
  46. // curl http://DOMAIN_NAME/v1/shelves/1
  47. option (google.api.http) = { get: "/v1/shelves/{shelf}" };
  48. }
  49. // Deletes a shelf, including all books that are stored on the shelf.
  50. rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) {
  51. // Client example - deletes the second shelf:
  52. // curl -X DELETE http://DOMAIN_NAME/v1/shelves/2
  53. option (google.api.http) = { delete: "/v1/shelves/{shelf}" };
  54. }
  55. // Returns a list of books on a shelf.
  56. rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {
  57. // Client example - list the books from the first shelf:
  58. // curl http://DOMAIN_NAME/v1/shelves/1/books
  59. option (google.api.http) = { get: "/v1/shelves/{shelf}/books" };
  60. }
  61. // Creates a new book.
  62. rpc CreateBook(CreateBookRequest) returns (Book) {
  63. // Client example - create a new book in the first shelf:
  64. // curl -d '{"author":"foo","title":"bar"}' http://DOMAIN_NAME/v1/shelves/1/books
  65. option (google.api.http) = {
  66. post: "/v1/shelves/{shelf}/books"
  67. body: "book"
  68. };
  69. }
  70. // Returns a specific book.
  71. rpc GetBook(GetBookRequest) returns (Book) {
  72. // Client example - get the first book from the second shelf:
  73. // curl http://DOMAIN_NAME/v1/shelves/2/books/1
  74. option (google.api.http) = { get: "/v1/shelves/{shelf}/books/{book}" };
  75. }
  76. // Deletes a book from a shelf.
  77. rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) {
  78. // Client example - delete the first book from the first shelf:
  79. // curl -X DELETE http://DOMAIN_NAME/v1/shelves/1/books/1
  80. option (google.api.http) = { delete: "/v1/shelves/{shelf}/books/{book}" };
  81. }
  82. }
  83. // A shelf resource.
  84. message Shelf {
  85. // A unique shelf id.
  86. int64 id = 1;
  87. // A theme of the shelf (fiction, poetry, etc).
  88. string theme = 2;
  89. }
  90. // A book resource.
  91. message Book {
  92. // A unique book id.
  93. int64 id = 1;
  94. // An author of the book.
  95. string author = 2;
  96. // A book title.
  97. string title = 3;
  98. }
  99. // Response to ListShelves call.
  100. message ListShelvesResponse {
  101. // Shelves in the bookstore.
  102. repeated Shelf shelves = 1;
  103. }
  104. // Request message for CreateShelf method.
  105. message CreateShelfRequest {
  106. // The shelf resource to create.
  107. Shelf shelf = 1;
  108. }
  109. // Request message for GetShelf method.
  110. message GetShelfRequest {
  111. // The ID of the shelf resource to retrieve.
  112. int64 shelf = 1;
  113. }
  114. // Request message for DeleteShelf method.
  115. message DeleteShelfRequest {
  116. // The ID of the shelf to delete.
  117. int64 shelf = 1;
  118. }
  119. // Request message for ListBooks method.
  120. message ListBooksRequest {
  121. // ID of the shelf which books to list.
  122. int64 shelf = 1;
  123. }
  124. // Response message to ListBooks method.
  125. message ListBooksResponse {
  126. // The books on the shelf.
  127. repeated Book books = 1;
  128. }
  129. // Request message for CreateBook method.
  130. message CreateBookRequest {
  131. // The ID of the shelf on which to create a book.
  132. int64 shelf = 1;
  133. // A book resource to create on the shelf.
  134. Book book = 2;
  135. }
  136. // Request message for GetBook method.
  137. message GetBookRequest {
  138. // The ID of the shelf from which to retrieve a book.
  139. int64 shelf = 1;
  140. // The ID of the book to retrieve.
  141. int64 book = 2;
  142. }
  143. // Request message for DeleteBook method.
  144. message DeleteBookRequest {
  145. // The ID of the shelf from which to delete a book.
  146. int64 shelf = 1;
  147. // The ID of the book to delete.
  148. int64 book = 2;
  149. }