Skip to content

Commit 5ab0c25

Browse files
qiwzhangJon Wayne Parrott
authored andcommitted
Add http_bookstore.proto for grpc transcoding. (#705)
1 parent fff2b68 commit 5ab0c25

File tree

1 file changed

+166
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)