annotate Core/RestApi/RestApi.h @ 322:7233461e2f61

new sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Jan 2013 15:33:53 +0100
parents 4eea080e6e7a
children 78a8eaa5f30b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../HttpServer/HttpHandler.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "RestApiPath.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "RestApiOutput.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 216
diff changeset
39 #include <list>
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 216
diff changeset
40
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 namespace Orthanc
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 class RestApi : public HttpHandler
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 private:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 class SharedCall
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 private:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 RestApiOutput* output_;
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
52 RestApi* context_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 const HttpHandler::Arguments* httpHeaders_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const RestApiPath::Components* uriComponents_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const UriComponents* trailing_;
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
56 const UriComponents* fullUri_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
58 protected:
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
59 static bool ParseJsonRequestInternal(Json::Value& result,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
60 const char* request);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
61
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 public:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 RestApiOutput& GetOutput()
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 return *output_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
68 RestApi& GetContext()
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
70 return *context_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
73 const UriComponents& GetFullUri() const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
75 return *fullUri_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
77
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
78 const UriComponents& GetTrailingUri() const
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
79 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
80 return *trailing_;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
81 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 std::string GetUriComponent(const std::string& name,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
84 const std::string& defaultValue) const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 return HttpHandler::GetArgument(*uriComponents_, name, defaultValue);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
88
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
89 std::string GetHttpHeader(const std::string& name,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
90 const std::string& defaultValue) const
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
91 {
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
92 return HttpHandler::GetArgument(*httpHeaders_, name, defaultValue);
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
93 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
94
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
95 virtual bool ParseJsonRequest(Json::Value& result) const = 0;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 public:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 class GetCall : public SharedCall
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 private:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 const HttpHandler::Arguments* getArguments_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 public:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 std::string GetArgument(const std::string& name,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
109 const std::string& defaultValue) const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return HttpHandler::GetArgument(*getArguments_, name, defaultValue);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
113
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
114 bool HasArgument(const std::string& name) const
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
115 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
116 return getArguments_->find(name) != getArguments_->end();
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
117 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
118
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
119 virtual bool ParseJsonRequest(Json::Value& result) const;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 class PutCall : public SharedCall
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 private:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 const std::string* data_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 public:
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
130 const std::string& GetPutBody() const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 return *data_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
134
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
135 virtual bool ParseJsonRequest(Json::Value& result) const
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
136 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
137 return ParseJsonRequestInternal(result, GetPutBody().c_str());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
138 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 class PostCall : public SharedCall
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 private:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 const std::string* data_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 public:
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
149 const std::string& GetPostBody() const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 return *data_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
153
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
154 virtual bool ParseJsonRequest(Json::Value& result) const
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
155 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
156 return ParseJsonRequestInternal(result, GetPostBody().c_str());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
157 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 class DeleteCall : public SharedCall
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
162 public:
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
163 virtual bool ParseJsonRequest(Json::Value& result) const
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
164 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
165 result.clear();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
166 return true;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
167 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 typedef void (*GetHandler) (GetCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 typedef void (*DeleteHandler) (DeleteCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 typedef void (*PutHandler) (PutCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 typedef void (*PostHandler) (PostCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 private:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 typedef std::list< std::pair<RestApiPath*, GetHandler> > GetHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 typedef std::list< std::pair<RestApiPath*, PutHandler> > PutHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 typedef std::list< std::pair<RestApiPath*, PostHandler> > PostHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 typedef std::list< std::pair<RestApiPath*, DeleteHandler> > DeleteHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 GetHandlers getHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 PutHandlers putHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 PostHandlers postHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 DeleteHandlers deleteHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 bool IsGetAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 bool IsPutAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 bool IsPostAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 bool IsDeleteAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 std::string GetAcceptedMethods(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 public:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 RestApi()
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 ~RestApi();
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 virtual bool IsServedUri(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 virtual void Handle(HttpOutput& output,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 const std::string& method,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 const UriComponents& uri,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 const Arguments& headers,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 const Arguments& getArguments,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 const std::string& postData);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 GetHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 PutHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 PostHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 DeleteHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }