开发者

RESTful Client API in C++

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 connect to Amazon Web Services and get the list of EC2 instances(and their details) available for given user account in C++开发者_StackOverflow中文版.

I know Amazon provides API's for this in Java, C#. But I want in C++. If Amazon provides in C++ too, that would be fine, Please guide me.

Your help is much appreciated.

Regards

Bharatha Selvan.


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.


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...


Did you try libaws ?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜