[[https://github.com/Corvusoft/restbed|Site web]] Licence AGPLv3 (GPLv3 + serveur). Exemple version v4.8 avec le serveur de l'exemple de base adapté avec l'ajout d'un client et de la sérialisation avec [[lib:cereal|cereal]]. { restbed::Service service; const auto foundation = std::make_shared()->SetB(1.); auto resource = std::make_shared(); resource->set_path("/resource"); resource->set_method_handler( "POST", [](const std::shared_ptr session) { const auto request = session->get_request(); int content_length = 0; content_length = request->get_header("Content-Length", content_length); session->fetch( static_cast(content_length), [](const std::shared_ptr sessionb, const restbed::Bytes& body) { std::string json_str(reinterpret_cast(body.data()), body.size()); std::stringstream is(json_str); cereal::JSONInputArchive iarchive(is); FoundationStrip foundation4; iarchive(foundation4); std::string retval = std::to_string(foundation4.B()); sessionb->close( restbed::OK, retval, {{"Content-Length", std::to_string(retval.length())}}); }); }); auto resource_close = std::make_shared(); resource_close->set_path("/quit"); resource_close->set_method_handler( "GET", [&service](const std::shared_ptr /*session*/) { service.stop(); }); auto settings = std::make_shared(); settings->set_port(1984); settings->set_default_header("Connection", "close"); service.publish(resource); service.publish(resource_close); std::thread server([&service, &settings]() { service.start(settings); }); while (!service.is_up()) ; { std::stringstream stream; { cereal::JSONOutputArchive archive(stream); archive(*foundation); } auto request = std::make_shared(); request->set_method("POST"); request->set_port(1984); request->set_host("localhost"); request->set_path("/resource"); request->set_body(stream.str()); request->set_header("Content-Length", std::to_string(stream.str().size())); auto response = restbed::Http::sync(request); restbed::Http::fetch(std::stoul(response->get_header("Content-Length")), response); JTEST_EQ(response->get_status_code(), 200); std::string json_str( reinterpret_cast(response->get_body().data()), response->get_body().size()); JTEST_EQ(std::stod(json_str), 1.0); } { auto request = std::make_shared(); request->set_method("GET"); request->set_port(1984); request->set_host("localhost"); request->set_path("/quit"); auto response = restbed::Http::sync(request); } server.join(); }