Corvusoft / restbed

Corvusoft's Restbed framework brings asynchronous RESTful functionality to C++14 applications.
http://www.corvusoft.co.uk
Other
1.93k stars 377 forks source link

Regarding the Static HTTP Class #507

Closed mjjackey closed 2 years ago

mjjackey commented 2 years ago

I have a question regarding the static HTTP Class. "The static HTTP class offers limited client capabilities for consuming RESTful services. This will be removed in future version and replaced with the Restless client framework." If so, which alternative can use in restbed, please? Actually, I compiled the code like this or the examples provided by the document. The vs compiler gave the error

Severity Code Description Project File Line Suppression State Error C4996 'restbed::Http': HTTP client is deprecated; we will release a complimentary client framework at a future date. Restbed_hello D:\src\vcpkg\installed\x64-windows\include\corvusoft\restbed\request.hpp 183.

#include <thread>
#include <memory>
#include <chrono>
#include <cstdlib>
#include <restbed>

using namespace std;
using namespace restbed;

void get_method_handler(const shared_ptr< Session > session)
{
    session->close(OK, "Hello, World!", { { "Content-Length", "13" }, { "Connection", "close" } });
}

void service_ready_handler(Service&)
{
    fprintf(stderr, "Hey! The service is up and running.");
}

void get_value(const shared_ptr< Session > session)
{
    const auto request = session->get_request();
    const string id = request->get_query_parameter("id");
    const string val = request->get_query_parameter("val");
    const string body = "id=" + id + ",val=" + val;
    session->close(OK, body, { { "Content-Length", ::to_string(body.size()) } });
}

int main(const int, const char**)
{
    auto resource = make_shared< Resource >();
    resource->set_path("/resource");
    resource->set_method_handler("GET", get_method_handler);

    auto resource3 = make_shared< Resource >();
    resource3->set_path("/query/param");
    resource3->set_method_handler("GET", get_value);

    auto settings = make_shared< Settings >();
    settings->set_port(1984);

    auto service = make_shared< Service >();
    service->publish(resource);
    service->publish(resource3);
    service->set_ready_handler(service_ready_handler);
    service->start(settings);

    return EXIT_SUCCESS;
}
mjjackey commented 2 years ago

I have found the same problem in #479