I am learning how to do this and all the examples with text / html. I tried to implement api rest server using JSON with POCO C ++ network libraries, but I'm not quite sure if this is the right way to do this.
void MyHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setStatus(HTTPResponse::HTTP_OK);
response.setContentType("application/json");
std::ostream& ostr = response.send();
string send("true");
ostr << send;
response.setContentLength(send.size());
}
It was originally implemented for hmtl connections as:
void MyHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setStatus(HTTPResponse::HTTP_OK);
response.setContentType("text/html");
std::ostream& ostr = response.send();
ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
ostr << "ConfigHandler";
ostr << "</p></body></html>";
}
Am I making the change correctly or am I missing something?
If anyone knows how to create a REST API using JSON with C ++ POCO libraries, he would really appreciate it.
Thanks in advance.
source
share