RESTful Client API in C++

后端 未结 4 1665
深忆病人
深忆病人 2021-01-18 05:26

Is there any open source library available that implements RESTful Client(library for interpreting HTTP requests as REST service calls) in C++ ?

My requirement is to

相关标签:
4条回答
  • 2021-01-18 06:04

    You need to parse XML. I suggest you try Qt C++ Toolkit it will give you a QHttp instance to make HTTP calls and QtXml module to parse the xml. This way you can create a C++ Rest Client.

    0 讨论(0)
  • 2021-01-18 06:13

    Restbed offers synchronous and asynchronous HTTP/ HTTPS client capabilities.

    #include <memory>
    #include <future>
    #include <cstdio>
    #include <cstdlib>
    #include <restbed>
    
    using namespace std;
    using namespace restbed;
    
    void print( const shared_ptr< Response >& response )
    {
        fprintf( stderr, "*** Response ***\n" );
        fprintf( stderr, "Status Code:    %i\n", response->get_status_code( ) );
        fprintf( stderr, "Status Message: %s\n", response->get_status_message( ).data( ) );
        fprintf( stderr, "HTTP Version:   %.1f\n", response->get_version( ) );
        fprintf( stderr, "HTTP Protocol:  %s\n", response->get_protocol( ).data( ) );
    
        for ( const auto header : response->get_headers( ) )
        {
            fprintf( stderr, "Header '%s' > '%s'\n", header.first.data( ), header.second.data( ) );
        }
    
        auto length = 0;
        response->get_header( "Content-Length", length );
    
        Http::fetch( length, response );
    
        fprintf( stderr, "Body:           %.*s...\n\n", 25, response->get_body( ).data( ) );
    }
    
    int main( const int, const char** )
    {
        auto request = make_shared< Request >( Uri( "http://www.corvusoft.co.uk:80/?query=search%20term" ) );
        request->set_header( "Accept", "*/*" );
        request->set_header( "Host", "www.corvusoft.co.uk" );
    
        auto response = Http::sync( request );
        print( response );
    
        auto future = Http::async( request, [ ]( const shared_ptr< Request >, const shared_ptr< Response > response )
        {
            fprintf( stderr, "Printing async response\n" );
            print( response );
        } );
    
        future.wait( );
    
        return EXIT_SUCCESS;
    }
    
    0 讨论(0)
  • 2021-01-18 06:16

    You should try the ffead-cpp web framework. It has a host of other features like Dependency Injection, Serialization, Limited Reflection, JSON etc to name a few. Do check it out...

    0 讨论(0)
  • 2021-01-18 06:17

    Did you try libaws ?

    0 讨论(0)
提交回复
热议问题