SOIL C++
C++ Unified Device Interface
|
HTTP Resource base class. More...
#include <Resource.h>
Public Member Functions | |
Resource () | |
Constructor. More... | |
~Resource () | |
Default Destructor. More... | |
virtual Response | handle (Request message, std::smatch match=std::smatch()) |
HTTP Handler. More... | |
virtual Response | handle_get (Request message, std::smatch match=std::smatch()) |
HTTP GET Handler. More... | |
virtual Response | handle_put (Request message, std::smatch match=std::smatch()) |
HTTP PUT Handler. More... | |
virtual Response | handle_post (Request message, std::smatch match=std::smatch()) |
HTTP POST Handler. More... | |
virtual Response | handle_delete (Request message, std::smatch match=std::smatch()) |
HTTP DELETE Handler. More... | |
virtual Response | handle_patch (Request message, std::smatch match=std::smatch()) |
HTTP PATCH Handler. More... | |
virtual Response | handle_options (Request message, std::smatch match=std::smatch()) |
HTTP OPTIONS Handler. More... | |
virtual Response | handle_head (Request message, std::smatch match=std::smatch()) |
HTTP HEAD Handler. More... | |
virtual Response | handle_exception (Request message, std::exception &exception, std::smatch match=std::smatch()) |
HTTP Exception handler. More... | |
Static Public Member Functions | |
static web::json::value | request_info (Request message, std::smatch match=std::smatch()) |
Request Info. More... | |
Protected Member Functions | |
void | apply_headers (Response &response) |
Apply headers. More... | |
Protected Attributes | |
std::vector< web::http::method > | allowed_methods |
Allowed methods. More... | |
std::string | content_type |
Content type. More... | |
std::string | allowed_origins |
Allowed Origins. More... | |
Base class for any resource that is implemented using this library. It should always be subclassed by the class implmenting the resource itself, and the relevant functions should be overriden. All HTTP business logic internally relies on the cpprestsdk library. The former internally uses widestrings, which leads to the need for conversion work at some places.
Definition at line 20 of file Resource.h.
HTTP::Resource::Resource | ( | ) |
Default Constructor, sets the above mentioned defaults for allowed_methods, content_type and allowed_origins
Definition at line 67 of file Resource.cpp.
HTTP::Resource::~Resource | ( | ) |
Default destructor, does no custom business logic.
Definition at line 74 of file Resource.cpp.
|
protected |
Apply headers to the HTTP response object. This function shoud be called in the handler before returning the repsonse object to the server.
[in,out] | response | Response object to act on. |
Definition at line 50 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests. By default, this function redirects to the more specifc ones based on the respective HTTP Verb. In case an exception occurs, it calls the exception handler.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented in SOIL::Element.
Definition at line 78 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests on a DELETE method. This function should be overridden by the implementation of the resource. Per default, it resorts to the internal fallback function.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented in SOIL::Object.
Definition at line 136 of file Resource.cpp.
|
virtual |
Handler function which can be called inside other handler functions to manage exceptions. It returns the request's information and exeption error text while setting the HTTP response to 500 (Internal Error).
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | exception | Exception to handle and to copy the error message from. |
[in] | match | Match result of the request path that led to this resource |
Definition at line 158 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests on a GET method. This function should be overridden by the implementation of the resource. Per default, it resorts to the internal fallback function.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented in SOIL::Object, SOIL::Parameter< T, x, y >, SOIL::Variable< T, x, y >, and SOIL::Function.
Definition at line 120 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests on a HEAD method. This function should be overridden by the implementation of the resource. Per default, it resorts to the internal fallback function.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Definition at line 153 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests on an OPTIONS method. This function should be overridden by the implementation of the resource. Per default, it resorts to the internal fallback function.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented in SOIL::Variable< T, x, y >.
Definition at line 148 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests on a PATCH method. This function should be overridden by the implementation of the resource. Per default, it resorts to the internal fallback function.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented in SOIL::Parameter< T, x, y >.
Definition at line 130 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests on a POST method. This function should be overridden by the implementation of the resource. Per default, it resorts to the internal fallback function.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented in SOIL::Function.
Definition at line 125 of file Resource.cpp.
|
virtual |
Handler that is called by the server on HTTP requests on a PUT method. This function should be overridden by the implementation of the resource. Per default, it resorts to the internal fallback function.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Reimplemented in SOIL::Object.
Definition at line 142 of file Resource.cpp.
|
static |
Extracts all sort of information from the request and returns it in JSON format. This is useful for fallback methods.
[in] | message | Incoming HTTP request as preprocessed by cpprestsdk |
[in] | match | Match result of the request path that led to this resource |
Definition at line 3 of file Resource.cpp.
|
protected |
List of allowed HTTP methods for this resource implemented as std::string
Defaults to all methods (GET, DELETE, PATCH, POST, OPTIONS, HEAD, PUT)
Definition at line 42 of file Resource.h.
|
protected |
Origins that are allowed, relavant when implementing web clients and running into CORS issues. Defaults to *
.
Definition at line 60 of file Resource.h.
|
protected |
Content type that is delivered by this resource. Defaults to application/json
Definition at line 50 of file Resource.h.