@@ -54,6 +54,22 @@ void {{classname}}::stopService() {
54
54
{
55
55
}
56
56
57
+ void { {classname} }{ {vendorExtensions.x-codegen-resourceName} }Resource::set_handler_{ {httpMethod} }(
58
+ std::function<std::pair <int, std::string >(
59
+ { {#allParams} }{ {{dataType} }} const & { {#hasMore} }, { {/hasMore} }{ {/allParams} }
60
+ )> handler) {
61
+ handler_{{httpMethod} }_ = std::move(handler);
62
+ }
63
+
64
+ { {#vendorExtensions.x-codegen-otherMethods} }
65
+ void { {classname} }{ {vendorExtensions.x-codegen-resourceName} }Resource::set_handler_{ {httpMethod} }(
66
+ std::function<std::pair <int, std::string >(
67
+ { {#allParams} }{ {{dataType} }} const & { {#hasMore} }, { {/hasMore} }{ {/allParams} }
68
+ )> handler) {
69
+ handler_{{httpMethod} }_ = std::move(handler);
70
+ }
71
+ { {/vendorExtensions.x-codegen-otherMethods} }
72
+
57
73
void { {classname} }{ {vendorExtensions.x-codegen-resourceName} }Resource::{ {httpMethod} }_method_handler(const std::shared_ptr<restbed::Session > session) {
58
74
59
75
const auto request = session-> get_request ();
@@ -65,12 +81,12 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
65
81
{
66
82
67
83
const auto request = session-> get_request ();
68
- std::string requestBody = restbed::String::format(" %.*s\n " , ( int ) body.size( ), body.data( ));
84
+ std::string file = restbed::String::format(" %.*s\n " , ( int ) body.size( ), body.data( ));
69
85
/**
70
- * Get body params or form params here from the requestBody string
86
+ * Get body params or form params here from the file string
71
87
*/
72
88
{{/hasBodyParam} }
73
-
89
+
74
90
{ {#hasPathParams} }
75
91
// Getting the path params
76
92
{ {#pathParams} }
@@ -79,7 +95,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
79
95
{ {/isPrimitiveType} }
80
96
{ {/pathParams} }
81
97
{ {/hasPathParams} }
82
-
98
+
83
99
{ {#hasQueryParams} }
84
100
// Getting the query params
85
101
{ {#queryParams} }
@@ -97,21 +113,25 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
97
113
{ {/isPrimitiveType} }
98
114
{ {/headerParams} }
99
115
{ {/hasHeaderParams} }
100
-
116
+
101
117
// Change the value of this variable to the appropriate response before sending the response
102
118
int status_code = 200;
103
-
104
- /**
105
- * Process the received information here
106
- */
107
-
119
+ std::string result = "successful operation";
120
+
121
+ if (handler_{ {httpMethod} }_)
122
+ {
123
+ std::tie(status_code, result) = handler_{{httpMethod} }_(
124
+ { {#allParams} }{ {paramName} }{ {#hasMore} }, { {/hasMore} }{ {/allParams} }
125
+ );
126
+ }
127
+
108
128
{ {#responses} }
109
129
if (status_code == { {code} }) {
110
130
{{#headers} }
111
131
// Description: { {description} }
112
132
session->set_header("{ {baseName} }", ""); // Change second param to your header value
113
133
{ {/headers} }
114
- session->close({ {code} }, "{ {message} }", { {" Connection" , " close" } });
134
+ session->close({ {code} }, result.empty() ? "{ {message} }" : std::move(result) , { {" Connection" , " close" } });
115
135
return;
116
136
}
117
137
{ {/responses} }
@@ -133,7 +153,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
133
153
{
134
154
135
155
const auto request = session-> get_request ();
136
- std::string requestBody = restbed::String::format(" %.*s\n " , ( int ) body.size( ), body.data( ));
156
+ std::string file = restbed::String::format(" %.*s\n " , ( int ) body.size( ), body.data( ));
137
157
{{/hasBodyParam} }
138
158
139
159
{ {#hasPathParams} }
@@ -144,7 +164,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
144
164
{ {/isPrimitiveType} }
145
165
{ {/pathParams} }
146
166
{ {/hasPathParams} }
147
-
167
+
148
168
{ {#hasQueryParams} }
149
169
// Getting the query params
150
170
{ {#queryParams} }
@@ -162,14 +182,18 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
162
182
{ {/isPrimitiveType} }
163
183
{ {/headerParams} }
164
184
{ {/hasHeaderParams} }
165
-
185
+
166
186
// Change the value of this variable to the appropriate response before sending the response
167
187
int status_code = 200;
168
-
169
- /**
170
- * Process the received information here
171
- */
172
-
188
+ std::string result = "successful operation";
189
+
190
+ if (handler_{ {httpMethod} }_)
191
+ {
192
+ std::tie(status_code, result) = handler_{{httpMethod} }_(
193
+ { {#allParams} }{ {paramName} }{ {#hasMore} }, { {/hasMore} }{ {/allParams} }
194
+ );
195
+ }
196
+
173
197
{ {#responses} }
174
198
if (status_code == { {code} }) {
175
199
{{#baseType} }
@@ -179,7 +203,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
179
203
// Description: { {description} }
180
204
session->set_header("{ {baseName} }", ""); // Change second param to your header value
181
205
{ {/headers} }
182
- session->close({ {code} }, "{ {message} }", { {" Connection" , " close" } });
206
+ session->close({ {code} }, result.empty() ? "{ {message} }" : std::move(result) , { {" Connection" , " close" } });
183
207
return;
184
208
}
185
209
{ {/responses} }
0 commit comments