hueplusplus  1.0.0
Public Member Functions | List of all members
hueplusplus::BaseHttpHandler Class Reference

Base class for classes that handle http requests and multicast requests. More...

#include <hueplusplus/BaseHttpHandler.h>

+ Inheritance diagram for hueplusplus::BaseHttpHandler:
+ Collaboration diagram for hueplusplus::BaseHttpHandler:

Public Member Functions

virtual ~BaseHttpHandler ()=default
 Virtual dtor. More...
 
std::string sendGetHTTPBody (const std::string &msg, const std::string &adr, int port=80) const override
 Send a message to a specified host and return the body of the response. More...
 
std::string sendHTTPRequest (const std::string &method, const std::string &uri, const std::string &contentType, const std::string &body, const std::string &adr, int port=80) const override
 Send a HTTP request with the given method to the specified host and return the body of the response. More...
 
std::string GETString (const std::string &uri, const std::string &contentType, const std::string &body, const std::string &adr, int port=80) const override
 Send a HTTP GET request to the specified host and return the body of the response. More...
 
std::string POSTString (const std::string &uri, const std::string &contentType, const std::string &body, const std::string &adr, int port=80) const override
 Send a HTTP POST request to the specified host and return the body of the response. More...
 
std::string PUTString (const std::string &uri, const std::string &contentType, const std::string &body, const std::string &adr, int port=80) const override
 Send a HTTP PUT request to the specified host and return the body of the response. More...
 
std::string DELETEString (const std::string &uri, const std::string &contentType, const std::string &body, const std::string &adr, int port=80) const override
 Send a HTTP DELETE request to the specified host and return the body of the response. More...
 
nlohmann::json GETJson (const std::string &uri, const nlohmann::json &body, const std::string &adr, int port=80) const override
 Send a HTTP GET request to the specified host and return the body of the response parsed as JSON. More...
 
nlohmann::json POSTJson (const std::string &uri, const nlohmann::json &body, const std::string &adr, int port=80) const override
 Send a HTTP POST request to the specified host and return the body of the response parsed as JSON. More...
 
nlohmann::json PUTJson (const std::string &uri, const nlohmann::json &body, const std::string &adr, int port=80) const override
 Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON. More...
 
nlohmann::json DELETEJson (const std::string &uri, const nlohmann::json &body, const std::string &adr, int port=80) const override
 Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON. More...
 
- Public Member Functions inherited from hueplusplus::IHttpHandler
virtual ~IHttpHandler ()=default
 Virtual dtor. More...
 
virtual std::string send (const std::string &msg, const std::string &adr, int port=80) const =0
 Send a message to a specified host and return the response. More...
 
virtual std::vector< std::string > sendMulticast (const std::string &msg, const std::string &adr="239.255.255.250", int port=1900, std::chrono::steady_clock::duration timeout=std::chrono::seconds(5)) const =0
 Send a multicast request with a specified message. More...
 

Detailed Description

Base class for classes that handle http requests and multicast requests.

Constructor & Destructor Documentation

◆ ~BaseHttpHandler()

virtual hueplusplus::BaseHttpHandler::~BaseHttpHandler ( )
virtualdefault

Virtual dtor.

Member Function Documentation

◆ DELETEJson()

nlohmann::json hueplusplus::BaseHttpHandler::DELETEJson ( const std::string &  uri,
const nlohmann::json &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON.

Parameters
uriUniform Resource Identifier in the request
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80
Returns
Parsed body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
nlohmann::json::parse_errorwhen the body could not be parsed

Implements hueplusplus::IHttpHandler.

◆ DELETEString()

std::string hueplusplus::BaseHttpHandler::DELETEString ( const std::string &  uri,
const std::string &  contentType,
const std::string &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP DELETE request to the specified host and return the body of the response.

Parameters
uriUniform Resource Identifier in the request
contentTypeMIME type of the body data e.g. "text/html", "application/json", ...
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80 that specifies the port to which the request is sent to. Default is 80
Returns
Body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body

Implements hueplusplus::IHttpHandler.

◆ GETJson()

nlohmann::json hueplusplus::BaseHttpHandler::GETJson ( const std::string &  uri,
const nlohmann::json &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP GET request to the specified host and return the body of the response parsed as JSON.

Parameters
uriUniform Resource Identifier in the request
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80
Returns
Parsed body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
nlohmann::json::parse_errorwhen the body could not be parsed

Implements hueplusplus::IHttpHandler.

◆ GETString()

std::string hueplusplus::BaseHttpHandler::GETString ( const std::string &  uri,
const std::string &  contentType,
const std::string &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP GET request to the specified host and return the body of the response.

Parameters
uriUniform Resource Identifier in the request
contentTypeMIME type of the body data e.g. "text/html", "application/json", ...
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80 that specifies the port to which the request is sent to. Default is 80
Returns
Body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body

Implements hueplusplus::IHttpHandler.

◆ POSTJson()

nlohmann::json hueplusplus::BaseHttpHandler::POSTJson ( const std::string &  uri,
const nlohmann::json &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP POST request to the specified host and return the body of the response parsed as JSON.

Parameters
uriUniform Resource Identifier in the request
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80
Returns
Parsed body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
nlohmann::json::parse_errorwhen the body could not be parsed

Implements hueplusplus::IHttpHandler.

◆ POSTString()

std::string hueplusplus::BaseHttpHandler::POSTString ( const std::string &  uri,
const std::string &  contentType,
const std::string &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP POST request to the specified host and return the body of the response.

Parameters
uriUniform Resource Identifier in the request
contentTypeMIME type of the body data e.g. "text/html", "application/json", ...
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80 that specifies the port to which the request is sent to. Default is 80
Returns
Body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body

Implements hueplusplus::IHttpHandler.

◆ PUTJson()

nlohmann::json hueplusplus::BaseHttpHandler::PUTJson ( const std::string &  uri,
const nlohmann::json &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON.

Parameters
uriUniform Resource Identifier in the request
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80
Returns
Parsed body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
nlohmann::json::parse_errorwhen the body could not be parsed

Implements hueplusplus::IHttpHandler.

◆ PUTString()

std::string hueplusplus::BaseHttpHandler::PUTString ( const std::string &  uri,
const std::string &  contentType,
const std::string &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP PUT request to the specified host and return the body of the response.

Parameters
uriUniform Resource Identifier in the request
contentTypeMIME type of the body data e.g. "text/html", "application/json", ...
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80 that specifies the port to which the request is sent to. Default is 80
Returns
Body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body

Implements hueplusplus::IHttpHandler.

◆ sendGetHTTPBody()

std::string hueplusplus::BaseHttpHandler::sendGetHTTPBody ( const std::string &  msg,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a message to a specified host and return the body of the response.

Parameters
msgThe message that should sent to the specified address
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80
Returns
The body of the response of the host as a string
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body

Implements hueplusplus::IHttpHandler.

◆ sendHTTPRequest()

std::string hueplusplus::BaseHttpHandler::sendHTTPRequest ( const std::string &  method,
const std::string &  uri,
const std::string &  contentType,
const std::string &  body,
const std::string &  adr,
int  port = 80 
) const
overridevirtual

Send a HTTP request with the given method to the specified host and return the body of the response.

Parameters
methodHTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ...
uriUniform Resource Identifier in the request
contentTypeMIME type of the body data e.g. "text/html", "application/json", ...
bodyRequest body, may be empty
adrIp or hostname in dotted decimal notation like "192.168.2.1"
portOptional port the request is sent to, default is 80
Returns
Body of the response of the host
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body

Implements hueplusplus::IHttpHandler.


The documentation for this class was generated from the following files: