Rename RegisterService to Bind and add is_regex parameter; indent public/protected/private by one space; refine rest example.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user