You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
C
62 lines
1.8 KiB
C
![]()
7 years ago
|
#ifndef BOOK_SERVICES_H_
|
||
|
#define BOOK_SERVICES_H_
|
||
|
|
||
|
#include "webcc/rest_service.h"
|
||
|
|
||
![]()
7 years ago
|
// -----------------------------------------------------------------------------
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
// BookListService handles the HTTP GET and returns the book list based on
|
||
![]()
7 years ago
|
// query parameters specified in the URL.
|
||
|
// The URL should be like:
|
||
|
// - /books
|
||
![]()
7 years ago
|
// - /books?name={BookName}
|
||
![]()
7 years ago
|
// The query parameters could be regular expressions.
|
||
![]()
7 years ago
|
class BookListService : public webcc::RestListService {
|
||
![]()
7 years ago
|
public:
|
||
|
BookListService(int sleep_seconds) : sleep_seconds_(sleep_seconds) {
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
protected:
|
||
|
// Return a list of books based on query parameters.
|
||
|
// URL examples:
|
||
|
// - /books
|
||
|
// - /books?name={BookName}
|
||
|
bool Get(const webcc::UrlQuery& query,
|
||
![]()
7 years ago
|
std::string* response_content) override;
|
||
![]()
7 years ago
|
|
||
|
// Create a new book.
|
||
|
bool Post(const std::string& request_content,
|
||
![]()
7 years ago
|
std::string* response_content) override;
|
||
|
|
||
|
private:
|
||
|
// Sleep for the client to test timeout control.
|
||
|
int sleep_seconds_ = 0;
|
||
![]()
7 years ago
|
};
|
||
|
|
||
![]()
7 years ago
|
// -----------------------------------------------------------------------------
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
// The URL is like '/books/{BookID}', and the 'url_sub_matches' parameter
|
||
|
// contains the matched book ID.
|
||
|
class BookDetailService : public webcc::RestDetailService {
|
||
![]()
7 years ago
|
public:
|
||
|
BookDetailService(int sleep_seconds) : sleep_seconds_(sleep_seconds) {
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
protected:
|
||
|
bool Get(const std::vector<std::string>& url_sub_matches,
|
||
![]()
7 years ago
|
const webcc::UrlQuery& query,
|
||
![]()
7 years ago
|
std::string* response_content) override;
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
bool Put(const std::vector<std::string>& url_sub_matches,
|
||
|
const std::string& request_content,
|
||
![]()
7 years ago
|
std::string* response_content) override;
|
||
|
|
||
|
bool Delete(const std::vector<std::string>& url_sub_matches) override;
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
private:
|
||
|
// Sleep for the client to test timeout control.
|
||
|
int sleep_seconds_ = 0;
|
||
![]()
7 years ago
|
};
|
||
|
|
||
|
#endif // BOOK_SERVICE_H_
|