Rename RegisterService to Bind and add is_regex parameter; indent public/protected/private by one space; refine rest example.

This commit is contained in:
Adam Gu
2018-05-22 15:45:38 +08:00
parent 1bab2da8f4
commit cdc61b4bf2
36 changed files with 182 additions and 235 deletions
+5 -4
View File
@@ -62,6 +62,7 @@ public:
if (it != books_.end()) {
it->title = book.title;
it->price = book.price;
return true;
}
return false;
}
@@ -162,10 +163,10 @@ bool BookDetailService::Get(const std::vector<std::string>& url_sub_matches,
return false;
}
// Update a book partially.
bool BookDetailService::Patch(const std::vector<std::string>& url_sub_matches,
const std::string& request_content,
std::string* response_content) {
// Update a book.
bool BookDetailService::Put(const std::vector<std::string>& url_sub_matches,
const std::string& request_content,
std::string* response_content) {
if (url_sub_matches.size() != 1) {
return false;
}
+3 -3
View File
@@ -35,9 +35,9 @@ class BookDetailService : public webcc::RestDetailService {
const webcc::UrlQuery& query,
std::string* response_content) final;
bool Patch(const std::vector<std::string>& url_sub_matches,
const std::string& request_content,
std::string* response_content) final;
bool Put(const std::vector<std::string>& url_sub_matches,
const std::string& request_content,
std::string* response_content) final;
bool Delete(const std::vector<std::string>& url_sub_matches) final;
};
+2 -4
View File
@@ -26,11 +26,9 @@ int main(int argc, char* argv[]) {
try {
webcc::RestServer server(port, workers);
server.RegisterService(std::make_shared<BookListService>(),
"/books");
server.Bind(std::make_shared<BookListService>(), "/books", false);
server.RegisterService(std::make_shared<BookDetailService>(),
"/book/(\\d+)");
server.Bind(std::make_shared<BookDetailService>(), "/book/(\\d+)", true);
server.Run();