19 #include <cpprest/http_listener.h> 31 class RESTServer::Impl
34 Impl(
const web::uri &uri);
43 RESTServer::Impl::Impl(
const web::uri &uri) : uri{uri} {}
45 RESTServer::Impl::~Impl() {}
47 void RESTServer::Impl::HandleRequest(
const http_request &request)
49 web::uri_builder builder(this->listener.uri());
50 builder.append(request.absolute_uri());
52 auto uriString = builder.to_uri().to_string();
55 response.set_body(U(
"There went something wrong after receiving the request."));
58 auto managerRef = context->GetServiceReference<IRESTManager>();
62 auto manager = context->GetService(managerRef);
66 web::json::value data = {};
67 if (request.headers().content_type() == U(
"application/json"))
69 data = request.extract_json().get();
73 auto begin = request.headers().begin();
74 auto end = request.headers().end();
76 for (; begin != end; ++begin)
78 headers.insert(mitk::RESTUtil::ParamMap::value_type(begin->first, begin->second));
81 response = manager->Handle(builder.to_uri(), data, request.method(), headers);
85 request.reply(response);
96 m_Impl->listener.support(std::bind(&Impl::HandleRequest, m_Impl.get(), _1));
97 m_Impl->listener.support(methods::OPTIONS, std::bind(&Impl::HandleRequest, m_Impl.get(), _1));
98 m_Impl->listener.open().wait();
103 m_Impl->listener.close().wait();
web::http::http_response http_response
DataCollection - Class to facilitate loading/accessing structured data.
web::http::experimental::listener::http_listener http_listener
web::http::methods methods
web::http::status_codes status_codes
void OpenListener()
Opens the listener and starts the listening process.
RESTServer(const web::uri &uri)
Creates an server listening to the given URI.
void CloseListener()
Closes the listener and stops the listening process.
web::http::http_response http_response
web::http::http_request http_request
web::http::http_request http_request
std::map< utility::string_t, utility::string_t > ParamMap
web::http::status_codes status_codes
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
web::http::methods methods