MCPcopy Create free account
hub / github.com/Stiffstream/restinio / create_request_handler

Function create_request_handler

dev/sample/extra_data_factory/main.cpp:190–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190auto create_request_handler()
191{
192 auto router = std::make_shared< express_router_t >();
193
194 router->http_get(
195 "/",
196 []( const auto & req, const auto & ) {
197 init_resp( req->create_response() )
198 .append_header(
199 restinio::http_field::content_type,
200 "text/plain; charset=utf-8" )
201 .set_body( "Hello world!")
202 .done();
203
204 return restinio::request_accepted();
205 } );
206
207 router->http_get(
208 "/json",
209 []( const auto & req, const auto & ) {
210 init_resp( req->create_response() )
211 .append_header(
212 restinio::http_field::content_type,
213 "application/json" )
214 .set_body( R"-({"message" : "Hello world!"})-")
215 .done();
216
217 return restinio::request_accepted();
218 } );
219
220 router->http_get(
221 "/html",
222 []( const auto & req, const auto & ) {
223 init_resp( req->create_response() )
224 .append_header(
225 restinio::http_field::content_type,
226 "text/html; charset=utf-8" )
227 .set_body(
228 "<html>\r\n"
229 " <head><title>Hello from RESTinio!</title></head>\r\n"
230 " <body>\r\n"
231 " <center><h1>Hello world</h1></center>\r\n"
232 " </body>\r\n"
233 "</html>\r\n" )
234 .done();
235
236 return restinio::request_accepted();
237 } );
238
239 router->http_get(
240 "/stats",
241 []( const auto & req, const auto & ) {
242 init_resp( req->create_response() )
243 .append_header(
244 restinio::http_field::content_type,
245 "text/plain; charset=utf-8" )
246 .set_body(
247 fmt::format(

Callers 1

mainFunction · 0.70

Calls 5

request_acceptedFunction · 0.85
create_responseMethod · 0.80
init_respFunction · 0.70
http_getMethod · 0.45
doneMethod · 0.45

Tested by

no test coverage detected