renamed server.resources to server.resource
This commit is contained in:
parent
00dbe0bdd5
commit
df5da942f6
3 changed files with 10 additions and 10 deletions
|
|
@ -17,7 +17,7 @@ int main() {
|
||||||
|
|
||||||
//Add resources using regular expression for path, a method-string, and an anonymous function
|
//Add resources using regular expression for path, a method-string, and an anonymous function
|
||||||
//POST-example for the path /string, responds the posted string
|
//POST-example for the path /string, responds the posted string
|
||||||
server.resources["^/string/?$"]["POST"]=[](ostream& response, Request& request) {
|
server.resource["^/string/?$"]["POST"]=[](ostream& response, Request& request) {
|
||||||
//Retrieve string from istream (*request.content)
|
//Retrieve string from istream (*request.content)
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
*request.content >> ss.rdbuf();
|
*request.content >> ss.rdbuf();
|
||||||
|
|
@ -34,7 +34,7 @@ int main() {
|
||||||
// "lastName": "Smith",
|
// "lastName": "Smith",
|
||||||
// "age": 25
|
// "age": 25
|
||||||
//}
|
//}
|
||||||
server.resources["^/json/?$"]["POST"]=[](ostream& response, Request& request) {
|
server.resource["^/json/?$"]["POST"]=[](ostream& response, Request& request) {
|
||||||
try {
|
try {
|
||||||
ptree pt;
|
ptree pt;
|
||||||
read_json(*request.content, pt);
|
read_json(*request.content, pt);
|
||||||
|
|
@ -50,7 +50,7 @@ int main() {
|
||||||
|
|
||||||
//GET-example for the path /info
|
//GET-example for the path /info
|
||||||
//Responds with request-information
|
//Responds with request-information
|
||||||
server.resources["^/info/?$"]["GET"]=[](ostream& response, Request& request) {
|
server.resource["^/info/?$"]["GET"]=[](ostream& response, Request& request) {
|
||||||
stringstream content_stream;
|
stringstream content_stream;
|
||||||
content_stream << "<h1>Request:</h1>";
|
content_stream << "<h1>Request:</h1>";
|
||||||
content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "<br>";
|
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)
|
//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
|
//For instance a request GET /match/123 will receive: 123
|
||||||
server.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, Request& request) {
|
server.resource["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, Request& request) {
|
||||||
string number=request.path_match[1];
|
string number=request.path_match[1];
|
||||||
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
|
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ int main() {
|
||||||
|
|
||||||
//Add resources using regular expression for path, a method-string, and an anonymous function
|
//Add resources using regular expression for path, a method-string, and an anonymous function
|
||||||
//POST-example for the path /string, responds the posted string
|
//POST-example for the path /string, responds the posted string
|
||||||
server.resources["^/string/?$"]["POST"]=[](ostream& response, Request& request) {
|
server.resource["^/string/?$"]["POST"]=[](ostream& response, Request& request) {
|
||||||
//Retrieve string from istream (*request.content)
|
//Retrieve string from istream (*request.content)
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
*request.content >> ss.rdbuf();
|
*request.content >> ss.rdbuf();
|
||||||
|
|
@ -34,7 +34,7 @@ int main() {
|
||||||
// "lastName": "Smith",
|
// "lastName": "Smith",
|
||||||
// "age": 25
|
// "age": 25
|
||||||
//}
|
//}
|
||||||
server.resources["^/json/?$"]["POST"]=[](ostream& response, Request& request) {
|
server.resource["^/json/?$"]["POST"]=[](ostream& response, Request& request) {
|
||||||
try {
|
try {
|
||||||
ptree pt;
|
ptree pt;
|
||||||
read_json(*request.content, pt);
|
read_json(*request.content, pt);
|
||||||
|
|
@ -50,7 +50,7 @@ int main() {
|
||||||
|
|
||||||
//GET-example for the path /info
|
//GET-example for the path /info
|
||||||
//Responds with request-information
|
//Responds with request-information
|
||||||
server.resources["^/info/?$"]["GET"]=[](ostream& response, Request& request) {
|
server.resource["^/info/?$"]["GET"]=[](ostream& response, Request& request) {
|
||||||
stringstream content_stream;
|
stringstream content_stream;
|
||||||
content_stream << "<h1>Request:</h1>";
|
content_stream << "<h1>Request:</h1>";
|
||||||
content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "<br>";
|
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)
|
//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
|
//For instance a request GET /match/123 will receive: 123
|
||||||
server.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, Request& request) {
|
server.resource["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, Request& request) {
|
||||||
string number=request.path_match[1];
|
string number=request.path_match[1];
|
||||||
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
|
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace SimpleWeb {
|
||||||
template <class socket_type>
|
template <class socket_type>
|
||||||
class ServerBase {
|
class ServerBase {
|
||||||
public:
|
public:
|
||||||
resource_type resources;
|
resource_type resource;
|
||||||
|
|
||||||
resource_type default_resource;
|
resource_type default_resource;
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace SimpleWeb {
|
||||||
void start() {
|
void start() {
|
||||||
//All resources with default_resource at the end of vector
|
//All resources with default_resource at the end of vector
|
||||||
//Used in the respond-method
|
//Used in the respond-method
|
||||||
for(auto it=resources.begin(); it!=resources.end();it++) {
|
for(auto it=resource.begin(); it!=resource.end();it++) {
|
||||||
all_resources.push_back(it);
|
all_resources.push_back(it);
|
||||||
}
|
}
|
||||||
for(auto it=default_resource.begin(); it!=default_resource.end();it++) {
|
for(auto it=default_resource.begin(); it!=default_resource.end();it++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue