@@ -54,6 +54,22 @@ void {{classname}}::stopService() {
5454{
5555}
5656
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+
5773void { {classname} }{ {vendorExtensions.x-codegen-resourceName} }Resource::{ {httpMethod} }_method_handler(const std::shared_ptr<restbed::Session > session) {
5874
5975 const auto request = session-> get_request ();
@@ -65,12 +81,12 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
6581 {
6682
6783 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( ));
6985 /**
70- * Get body params or form params here from the requestBody string
86+ * Get body params or form params here from the file string
7187 */
7288 {{/hasBodyParam} }
73-
89+
7490 { {#hasPathParams} }
7591 // Getting the path params
7692 { {#pathParams} }
@@ -79,7 +95,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
7995 { {/isPrimitiveType} }
8096 { {/pathParams} }
8197 { {/hasPathParams} }
82-
98+
8399 { {#hasQueryParams} }
84100 // Getting the query params
85101 { {#queryParams} }
@@ -97,21 +113,25 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
97113 { {/isPrimitiveType} }
98114 { {/headerParams} }
99115 { {/hasHeaderParams} }
100-
116+
101117 // Change the value of this variable to the appropriate response before sending the response
102118 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+
108128 { {#responses} }
109129 if (status_code == { {code} }) {
110130 {{#headers} }
111131 // Description: { {description} }
112132 session->set_header("{ {baseName} }", ""); // Change second param to your header value
113133 { {/headers} }
114- session->close({ {code} }, "{ {message} }", { {" Connection" , " close" } });
134+ session->close({ {code} }, result.empty() ? "{ {message} }" : std::move(result) , { {" Connection" , " close" } });
115135 return;
116136 }
117137 { {/responses} }
@@ -133,7 +153,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
133153 {
134154
135155 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( ));
137157 {{/hasBodyParam} }
138158
139159 { {#hasPathParams} }
@@ -144,7 +164,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
144164 { {/isPrimitiveType} }
145165 { {/pathParams} }
146166 { {/hasPathParams} }
147-
167+
148168 { {#hasQueryParams} }
149169 // Getting the query params
150170 { {#queryParams} }
@@ -162,14 +182,18 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
162182 { {/isPrimitiveType} }
163183 { {/headerParams} }
164184 { {/hasHeaderParams} }
165-
185+
166186 // Change the value of this variable to the appropriate response before sending the response
167187 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+
173197 { {#responses} }
174198 if (status_code == { {code} }) {
175199 {{#baseType} }
@@ -179,7 +203,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
179203 // Description: { {description} }
180204 session->set_header("{ {baseName} }", ""); // Change second param to your header value
181205 { {/headers} }
182- session->close({ {code} }, "{ {message} }", { {" Connection" , " close" } });
206+ session->close({ {code} }, result.empty() ? "{ {message} }" : std::move(result) , { {" Connection" , " close" } });
183207 return;
184208 }
185209 { {/responses} }
0 commit comments