How to implement a REST API server using the POCO C ++ network library using JSON?

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.

+4
source share
1 answer

Poco ++ - REST API ++, . p >

GitHub API, ++, Poco.

+1

Source: https://habr.com/ru/post/1628498/


All Articles