Skip to content

Commit c9db9b3

Browse files
author
Sebastiano Merlino
committed
Enhanced the level of detail of hello_world example
1 parent 51ac8cf commit c9db9b3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

examples/hello_world.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
#include <httpserver.hpp>
2+
#include <iostream>
23

34
using namespace httpserver;
45

56
class hello_world_resource : public http_resource<hello_world_resource> {
67
public:
78
void render(const http_request&, http_response**);
9+
void set_some_data(const std::string &s) {data = s;}
10+
std::string data;
811
};
912

1013
//using the render method you are able to catch each type of request you receive
1114
void hello_world_resource::render(const http_request& req, http_response** res)
1215
{
16+
//it is possible to store data inside the resource object that can be altered
17+
//through the requests
18+
std::cout << "Data was: " << data << std::endl;
19+
std::string datapar = req.get_arg("data");
20+
set_some_data(datapar == "" ? "no data passed!!!" : datapar);
21+
std::cout << "Now data is:" << data << std::endl;
22+
1323
//it is possible to send a response initializing an http_string_response
1424
//that reads the content to send in response from a string.
1525
*res = new http_string_response("Hello World!!!", 200);

0 commit comments

Comments
 (0)