comparison Core/RestApi/RestApi.h @ 304:4eea080e6e7a

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Dec 2012 14:57:18 +0100
parents 4031f73fe0e4
children 78a8eaa5f30b
comparison
equal deleted inserted replaced
303:c76a35a85c69 304:4eea080e6e7a
53 const HttpHandler::Arguments* httpHeaders_; 53 const HttpHandler::Arguments* httpHeaders_;
54 const RestApiPath::Components* uriComponents_; 54 const RestApiPath::Components* uriComponents_;
55 const UriComponents* trailing_; 55 const UriComponents* trailing_;
56 const UriComponents* fullUri_; 56 const UriComponents* fullUri_;
57 57
58 protected:
59 static bool ParseJsonRequestInternal(Json::Value& result,
60 const char* request);
61
58 public: 62 public:
59 RestApiOutput& GetOutput() 63 RestApiOutput& GetOutput()
60 { 64 {
61 return *output_; 65 return *output_;
62 } 66 }
85 std::string GetHttpHeader(const std::string& name, 89 std::string GetHttpHeader(const std::string& name,
86 const std::string& defaultValue) const 90 const std::string& defaultValue) const
87 { 91 {
88 return HttpHandler::GetArgument(*httpHeaders_, name, defaultValue); 92 return HttpHandler::GetArgument(*httpHeaders_, name, defaultValue);
89 } 93 }
94
95 virtual bool ParseJsonRequest(Json::Value& result) const = 0;
90 }; 96 };
91 97
92 98
93 public: 99 public:
94 class GetCall : public SharedCall 100 class GetCall : public SharedCall
107 113
108 bool HasArgument(const std::string& name) const 114 bool HasArgument(const std::string& name) const
109 { 115 {
110 return getArguments_->find(name) != getArguments_->end(); 116 return getArguments_->find(name) != getArguments_->end();
111 } 117 }
118
119 virtual bool ParseJsonRequest(Json::Value& result) const;
112 }; 120 };
113 121
114 class PutCall : public SharedCall 122 class PutCall : public SharedCall
115 { 123 {
116 friend class RestApi; 124 friend class RestApi;
117 125
118 private: 126 private:
119 const std::string* data_; 127 const std::string* data_;
120 128
121 public: 129 public:
122 const std::string& GetPutBody() 130 const std::string& GetPutBody() const
123 { 131 {
124 return *data_; 132 return *data_;
125 } 133 }
134
135 virtual bool ParseJsonRequest(Json::Value& result) const
136 {
137 return ParseJsonRequestInternal(result, GetPutBody().c_str());
138 }
126 }; 139 };
127 140
128 class PostCall : public SharedCall 141 class PostCall : public SharedCall
129 { 142 {
130 friend class RestApi; 143 friend class RestApi;
131 144
132 private: 145 private:
133 const std::string* data_; 146 const std::string* data_;
134 147
135 public: 148 public:
136 const std::string& GetPostBody() 149 const std::string& GetPostBody() const
137 { 150 {
138 return *data_; 151 return *data_;
139 } 152 }
153
154 virtual bool ParseJsonRequest(Json::Value& result) const
155 {
156 return ParseJsonRequestInternal(result, GetPostBody().c_str());
157 }
140 }; 158 };
141 159
142 class DeleteCall : public SharedCall 160 class DeleteCall : public SharedCall
143 { 161 {
162 public:
163 virtual bool ParseJsonRequest(Json::Value& result) const
164 {
165 result.clear();
166 return true;
167 }
144 }; 168 };
145 169
146 typedef void (*GetHandler) (GetCall& call); 170 typedef void (*GetHandler) (GetCall& call);
147 171
148 typedef void (*DeleteHandler) (DeleteCall& call); 172 typedef void (*DeleteHandler) (DeleteCall& call);