HTPP Server.
More...
#include <Server.h>
Abstraction layer for an HTTP Server implemented using the cpprestsdk.
- Todo:
- cpprestsdk is now in maintenance mode, if this library shall be in the very long term, a substitute may need to be found.
Definition at line 21 of file Server.h.
◆ Server()
HTTP::Server::Server |
( |
std::string |
url | ) |
|
Constructor setting up the server, but not accepting connections upon construction.
- Parameters
-
[in] | url | Base URL, e.g. http://localhost:8000 . Please note that the hostname part indicates the interface on which the server will listen. |
- Postcondition
- When using another interface than localhost, Windows will prompt for firewall permissions. In general firewalls should be considered when working with HTTP Servers.
-
HTTPS is currently not implemented here - The current recommendation is that a reverse proxy is used for this purpose, e.g. NGINX or Microsoft IIS.
Definition at line 9 of file Server.cpp.
◆ ~Server()
HTTP::Server::~Server |
( |
| ) |
|
Standard Destructor without custom logic. The server will be closed upon destruction, so make sure that the lifecycle of the server objects is apropriately managed in your application.
Definition at line 15 of file Server.cpp.
◆ add()
void HTTP::Server::add |
( |
std::string |
path, |
|
|
std::shared_ptr< Resource > |
resource |
|
) |
| |
Register a resource by means of a matching expression and shared pointer reference. Please note that the order of adding resources to the sever determines the precedence in matching. The frst matching resource will handle the request. This is a common source of errors. This function can be called dynamically at runtime, also when the server is already running.
- Parameters
-
[in] | path | Path of the resource written as regular expression. Use L"/?(.*)" to match everything under the root path. The path simulatenously acts as unique identifier. |
[in] | resource | Shared pointer to the resource that shall handle this path. Please be aware of the lifecycle in case you interfere with the pointers. |
Definition at line 39 of file Server.cpp.
◆ close()
void HTTP::Server::close |
( |
| ) |
|
|
inline |
Open the server for incoming connections. This is a blocking call.
Definition at line 91 of file Server.h.
◆ open()
void HTTP::Server::open |
( |
| ) |
|
|
inline |
Open the server for incoming connections. This is a blocking call.
Definition at line 84 of file Server.h.
◆ remove()
void HTTP::Server::remove |
( |
std::string |
path | ) |
|
Remove a previously registered resource. This function can be called dynamically at runtime, also when the server is already running.
- Parameters
-
[in] | path | Path of the resource written as regular expression. Use L"/?(.*)" which was used to add the resource and acts an unique identifier. |
Definition at line 44 of file Server.cpp.
The documentation for this class was generated from the following files: