Add query parameters to RestService::Handle()
This commit is contained in:
@@ -117,6 +117,7 @@ static bool BookFromJson(const std::string& json, Book* book) {
|
||||
|
||||
bool BookListService::Handle(const std::string& http_method,
|
||||
const std::vector<std::string>& url_sub_matches,
|
||||
const std::map<std::string, std::string>& query,
|
||||
const std::string& request_content,
|
||||
std::string* response_content) {
|
||||
if (http_method == webcc::kHttpGet) {
|
||||
@@ -149,6 +150,7 @@ bool BookListService::Handle(const std::string& http_method,
|
||||
|
||||
bool BookDetailService::Handle(const std::string& http_method,
|
||||
const std::vector<std::string>& url_sub_matches,
|
||||
const std::map<std::string, std::string>& query,
|
||||
const std::string& request_content,
|
||||
std::string* response_content) {
|
||||
if (url_sub_matches.size() != 1) {
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
|
||||
bool Handle(const std::string& http_method,
|
||||
const std::vector<std::string>& url_sub_matches,
|
||||
const std::map<std::string, std::string>& query,
|
||||
const std::string& request_content,
|
||||
std::string* response_content) override;
|
||||
};
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
|
||||
bool Handle(const std::string& http_method,
|
||||
const std::vector<std::string>& url_sub_matches,
|
||||
const std::map<std::string, std::string>& query,
|
||||
const std::string& request_content,
|
||||
std::string* response_content) override;
|
||||
};
|
||||
|
||||
@@ -84,10 +84,14 @@ HttpStatus::Enum RestRequestHandler::HandleSession(HttpSessionPtr session) {
|
||||
return HttpStatus::kBadRequest;
|
||||
}
|
||||
|
||||
// TODO: Only for GET?
|
||||
Url::Query query = Url::SplitQuery(url.query());
|
||||
|
||||
// TODO: Error handling.
|
||||
std::string content;
|
||||
service->Handle(session->request().method(),
|
||||
sub_matches,
|
||||
query,
|
||||
session->request().content(),
|
||||
&content);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef WEBCC_REST_SERVICE_H_
|
||||
#define WEBCC_REST_SERVICE_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -16,10 +17,15 @@ public:
|
||||
}
|
||||
|
||||
// Handle REST request, output the response.
|
||||
// Both the request and response parameters should be JSON.
|
||||
// TODO: Query parameters.
|
||||
// \param http_method GET, POST, etc.
|
||||
// \param url_sub_matches The regex sub-matches in the URL,
|
||||
// usually resource ID.
|
||||
// \param query Query parameters in the URL, key value pairs.
|
||||
// \param request_content Request JSON.
|
||||
// \param response_content Output response JSON.
|
||||
virtual bool Handle(const std::string& http_method,
|
||||
const std::vector<std::string>& url_sub_matches,
|
||||
const std::map<std::string, std::string>& query,
|
||||
const std::string& request_content,
|
||||
std::string* response_content) = 0;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ class TestRestService : public RestService {
|
||||
public:
|
||||
bool Handle(const std::string& http_method,
|
||||
const std::vector<std::string>& url_sub_matches,
|
||||
const std::map<std::string, std::string>& query,
|
||||
const std::string& request_content,
|
||||
std::string* response_content) override {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user