// Copyright 2016 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// syntax = "proto3"; package endpoints.examples.bookstore; option java_multiple_files = true; option java_outer_classname = "BookstoreProto"; option java_package = "com.google.endpoints.examples.bookstore"; import "google/api/annotations.proto"; import "google/protobuf/empty.proto"; // A simple Bookstore API. // // The API manages shelves and books resources. Shelves contain books. service Bookstore { // Returns a list of all shelves in the bookstore. rpc ListShelves(google.protobuf.Empty) returns (ListShelvesResponse) { // Define HTTP mapping. // Client example (Assuming your service is hosted at the given 'DOMAIN_NAME'): // curl http://DOMAIN_NAME/v1/shelves option (google.api.http) = { get: "/v1/shelves" }; } // Creates a new shelf in the bookstore. rpc CreateShelf(CreateShelfRequest) returns (Shelf) { // Client example: // curl -d '{"theme":"Music"}' http://DOMAIN_NAME/v1/shelves option (google.api.http) = { post: "/v1/shelves" body: "shelf" }; } // Returns a specific bookstore shelf. rpc GetShelf(GetShelfRequest) returns (Shelf) { // Client example - returns the first shelf: // curl http://DOMAIN_NAME/v1/shelves/1 option (google.api.http) = { get: "/v1/shelves/{shelf}" }; } // Deletes a shelf, including all books that are stored on the shelf. rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) { // Client example - deletes the second shelf: // curl -X DELETE http://DOMAIN_NAME/v1/shelves/2 option (google.api.http) = { delete: "/v1/shelves/{shelf}" }; } // Returns a list of books on a shelf. rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) { // Client example - list the books from the first shelf: // curl http://DOMAIN_NAME/v1/shelves/1/books option (google.api.http) = { get: "/v1/shelves/{shelf}/books" }; } // Creates a new book. rpc CreateBook(CreateBookRequest) returns (Book) { // Client example - create a new book in the first shelf: // curl -d '{"author":"foo","title":"bar"}' http://DOMAIN_NAME/v1/shelves/1/books option (google.api.http) = { post: "/v1/shelves/{shelf}/books" body: "book" }; } // Returns a specific book. rpc GetBook(GetBookRequest) returns (Book) { // Client example - get the first book from the second shelf: // curl http://DOMAIN_NAME/v1/shelves/2/books/1 option (google.api.http) = { get: "/v1/shelves/{shelf}/books/{book}" }; } // Deletes a book from a shelf. rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) { // Client example - delete the first book from the first shelf: // curl -X DELETE http://DOMAIN_NAME/v1/shelves/1/books/1 option (google.api.http) = { delete: "/v1/shelves/{shelf}/books/{book}" }; } } // A shelf resource. message Shelf { // A unique shelf id. int64 id = 1; // A theme of the shelf (fiction, poetry, etc). string theme = 2; } // A book resource. message Book { // A unique book id. int64 id = 1; // An author of the book. string author = 2; // A book title. string title = 3; } // Response to ListShelves call. message ListShelvesResponse { // Shelves in the bookstore. repeated Shelf shelves = 1; } // Request message for CreateShelf method. message CreateShelfRequest { // The shelf resource to create. Shelf shelf = 1; } // Request message for GetShelf method. message GetShelfRequest { // The ID of the shelf resource to retrieve. int64 shelf = 1; } // Request message for DeleteShelf method. message DeleteShelfRequest { // The ID of the shelf to delete. int64 shelf = 1; } // Request message for ListBooks method. message ListBooksRequest { // ID of the shelf which books to list. int64 shelf = 1; } // Response message to ListBooks method. message ListBooksResponse { // The books on the shelf. repeated Book books = 1; } // Request message for CreateBook method. message CreateBookRequest { // The ID of the shelf on which to create a book. int64 shelf = 1; // A book resource to create on the shelf. Book book = 2; } // Request message for GetBook method. message GetBookRequest { // The ID of the shelf from which to retrieve a book. int64 shelf = 1; // The ID of the book to retrieve. int64 book = 2; } // Request message for DeleteBook method. message DeleteBookRequest { // The ID of the shelf from which to delete a book. int64 shelf = 1; // The ID of the book to delete. int64 book = 2; }