-
Notifications
You must be signed in to change notification settings - Fork 888
Quickstart
ipkn edited this page Jan 8, 2015
·
4 revisions
// ex1.cpp
#include "crow_all.h"
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([]{
return "Hello, world!";
});
app
.port(8080)
.run();
}
This is the simplest web server using Crow.
Compile and run with following command:
$ g++ ex1.cpp -std=c++11 -O3 -lboost_system -lboost_thread
$ ./a.out
(2015-01-08 13:37:43) [INFO ] Crow/0.1 server is running, local port 8080
crow::SimpleApp
is the main class for our HTTP server. It's Simple
because SimpleApp
doesn't have any middlewares. For details about middleware, see middleware section.
CROW_ROUTE
macro registers a handler function for each url pattern. In this case, a HTTP request to url /
will return a Hello, World!
response with 200 OK
status code. Other url returns 404 error.
app
instance has several methods to configure the server. For example, .port(number)
method changes the listening port and .multithreaded()
method turns on multiple thread mode for serving requests.
Finally app.run()
is called and Crow starts to serve.