A simple reactor based HTTP server.
More...
#include <http_server.hpp>
|
| server (unsigned short port) |
|
| server (unsigned short port, const std::string &dir) |
|
void | run () |
|
void | shutdown () |
|
bool | is_running () const |
|
template<class RequestHandler > |
void | on_get (const std::string &route, RequestHandler request_handler) |
|
template<class RequestHandler > |
void | on_post (const std::string &route, RequestHandler request_handler) |
|
template<class RequestHandler > |
void | on_put (const std::string &route, RequestHandler request_handler) |
|
template<class RequestHandler > |
void | on_remove (const std::string &route, RequestHandler request_handler) |
|
void | add_middleware (const std::shared_ptr< middleware > &mware) |
|
void | add_routing_middleware () |
|
A simple reactor based HTTP server.
This class implements a single threaded HTTP server based on the reactor implementation.
It provides four HTTP methods for which a route (path) and callback pair can be registered.
The callback takes a http::request object as input parameter and returns a http::response object.
To use the automatic routing of incoming requests by path a routing middleware can be added via calling add_routing_middle_ware().
◆ server() [1/2]
matador::http::server::server |
( |
unsigned short |
port | ) |
|
|
explicit |
Creates a HTTP server at the given port.
- Parameters
-
port | Port on which the server listens for connections. |
◆ server() [2/2]
matador::http::server::server |
( |
unsigned short |
port, |
|
|
const std::string & |
dir |
|
) |
| |
Creates a HTTP server at the given port. The given directory path is used as root directory when serving files.
- Parameters
-
port | Port on which the server listens for connections. |
dir | Directory to serve files from |
◆ add_middleware()
void matador::http::server::add_middleware |
( |
const std::shared_ptr< middleware > & |
mware | ) |
|
Adds the given middleware to the middleware pipeline.
Note: The last added middleware will be executed at first.
- Parameters
-
◆ add_routing_middleware()
void matador::http::server::add_routing_middleware |
( |
| ) |
|
Adds the routing middleware to the middleware pipeline. It handles that the correct callback is executed depending on the route and the method of the incoming request.
◆ is_running()
bool matador::http::server::is_running |
( |
| ) |
const |
Returns true if the server is running
- Returns
- True if the server is running
◆ on_get()
template<class RequestHandler >
void matador::http::server::on_get |
( |
const std::string & |
route, |
|
|
RequestHandler |
request_handler |
|
) |
| |
|
inline |
Registers a HTTP GET method callback for the given route.
- Template Parameters
-
RequestHandler | Type of the callback |
- Parameters
-
route | The route for the callback |
request_handler | The GET callback to be executed |
◆ on_post()
template<class RequestHandler >
void matador::http::server::on_post |
( |
const std::string & |
route, |
|
|
RequestHandler |
request_handler |
|
) |
| |
|
inline |
Registers a HTTP POST method callback for the given route.
- Template Parameters
-
RequestHandler | Type of the callback |
- Parameters
-
route | The route for the callback |
request_handler | The POST callback to be executed |
◆ on_put()
template<class RequestHandler >
void matador::http::server::on_put |
( |
const std::string & |
route, |
|
|
RequestHandler |
request_handler |
|
) |
| |
|
inline |
Registers a HTTP PUT method callback for the given route.
- Template Parameters
-
RequestHandler | Type of the callback |
- Parameters
-
route | The route for the callback |
request_handler | The PUT callback to be executed |
◆ on_remove()
template<class RequestHandler >
void matador::http::server::on_remove |
( |
const std::string & |
route, |
|
|
RequestHandler |
request_handler |
|
) |
| |
|
inline |
Registers a HTTP DELETE method callback for the given route.
- Template Parameters
-
RequestHandler | Type of the callback |
- Parameters
-
route | The route for the callback |
request_handler | The DELETE callback to be executed |
◆ run()
void matador::http::server::run |
( |
| ) |
|
◆ shutdown()
void matador::http::server::shutdown |
( |
| ) |
|
The documentation for this class was generated from the following file:
- matador/http/http_server.hpp