minor changes
This commit is contained in:
parent
8e52412a2e
commit
b8c3556ded
2 changed files with 14 additions and 14 deletions
|
|
@ -13,11 +13,11 @@ using namespace boost::property_tree;
|
|||
|
||||
int main() {
|
||||
//HTTP-server at port 8080 using 4 threads
|
||||
Server<HTTP> httpserver(8080, 4);
|
||||
Server<HTTP> server(8080, 4);
|
||||
|
||||
//Add resources using regular expression for path, a method-string, and an anonymous function
|
||||
//POST-example for the path /string, responds the posted string
|
||||
httpserver.resources["^/string/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
server.resources["^/string/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
//Retrieve string from istream (*request.content)
|
||||
stringstream ss;
|
||||
*request.content >> ss.rdbuf();
|
||||
|
|
@ -34,7 +34,7 @@ int main() {
|
|||
// "lastName": "Smith",
|
||||
// "age": 25
|
||||
//}
|
||||
httpserver.resources["^/json/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
server.resources["^/json/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
try {
|
||||
ptree pt;
|
||||
read_json(*request.content, pt);
|
||||
|
|
@ -50,7 +50,7 @@ int main() {
|
|||
|
||||
//GET-example for the path /info
|
||||
//Responds with request-information
|
||||
httpserver.resources["^/info/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
server.resources["^/info/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
stringstream content_stream;
|
||||
content_stream << "<h1>Request:</h1>";
|
||||
content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "<br>";
|
||||
|
|
@ -66,7 +66,7 @@ int main() {
|
|||
|
||||
//GET-example for the path /match/[number], responds with the matched string in path (number)
|
||||
//For instance a request GET /match/123 will receive: 123
|
||||
httpserver.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
server.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
string number=path_match[1];
|
||||
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
|
||||
};
|
||||
|
|
@ -75,7 +75,7 @@ int main() {
|
|||
//Will respond with content in the web/-directory, and its subdirectories.
|
||||
//Default file: index.html
|
||||
//Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server
|
||||
httpserver.default_resource["^/?(.*)$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
server.default_resource["^/?(.*)$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) {
|
||||
string filename="web/";
|
||||
|
||||
string path=path_match[1];
|
||||
|
|
@ -119,7 +119,7 @@ int main() {
|
|||
};
|
||||
|
||||
//Start HTTP-server
|
||||
httpserver.start();
|
||||
server.start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue