#ifndef EXAMPLE_REST_BOOK_SERVER_SERVICES_H_ #define EXAMPLE_REST_BOOK_SERVER_SERVICES_H_ #include #include #include "webcc/rest_service.h" // ----------------------------------------------------------------------------- // BookListService handles the HTTP GET and returns the book list based on // query parameters specified in the URL. // The URL should be like: // - /books // - /books?name={BookName} // The query parameters could be regular expressions. class BookListService : public webcc::RestListService { public: explicit BookListService(int sleep_seconds) : sleep_seconds_(sleep_seconds) { } protected: // Return a list of books based on query parameters. // URL examples: // - /books // - /books?name={BookName} bool Get(const webcc::UrlQuery& query, std::string* response_content) override; // Create a new book. bool Post(const std::string& request_content, std::string* response_content) override; private: // Sleep for the client to test timeout control. int sleep_seconds_ = 0; }; // ----------------------------------------------------------------------------- // The URL is like '/books/{BookID}', and the 'url_sub_matches' parameter // contains the matched book ID. class BookDetailService : public webcc::RestDetailService { public: explicit BookDetailService(int sleep_seconds) : sleep_seconds_(sleep_seconds) { } protected: bool Get(const std::vector& url_sub_matches, const webcc::UrlQuery& query, std::string* response_content) override; bool Put(const std::vector& url_sub_matches, const std::string& request_content, std::string* response_content) override; bool Delete(const std::vector& url_sub_matches) override; private: // Sleep for the client to test timeout control. int sleep_seconds_ = 0; }; #endif // EXAMPLE_REST_BOOK_SERVER_SERVICES_H_