HTTP API Help

Jun 17, 2014 at 7:46 PM
Hi All,

I'm using Casablanca to help me use my C++ code to make HTTP requests for an API for a video editing software (vMix). The way that API is set up, I need to make a separate request for each function I want to perform in the vMix software. Does anyone have any suggestions for a simple way to code multiple requests in a single script?

Thanks
Coordinator
Jun 18, 2014 at 6:09 PM
Hi mrm63,

I'm a little unsure exactly what you are asking? Can you be more specific about what you mean by "a simple way to code multiple requests in a single script"? Basically all that needs to be done is to create an instance of our http_client class and then you can make as many HTTP requests as you'd like. I recommend you start by following our http_client tutorial.

Thanks,
Steve
Jun 23, 2014 at 1:44 PM
Hi Steve,

Forgive me--I'm new at this. Basically what I need to do is use my C++ code to control functions on a video editing software I'm using, which is done through HTTP requests. The http_client tutorial I think does a lot more than I need. Basically I need my script to be able to make multiple requests (because each request only corresponds to one function on the video editing software). So I guess I'm trying to figure out what portions of the tutorial are relevant for my goals, as I don't need to perform a search, or take any data back from the server itself.

So lets say my requests are in the syntax of:

http://10.180.90.171:8080/api/?Function=Cut
http://10.180.90.171:8080/api/?Function=Fade
http://10.180.90.171:8080/api/?Function=Zoom


And I want to perform all three in a single script. How would I accomplish that (hopefully something I could embed within a while loop of a larger script)

Thank you and I appreciate your patience!
Matt
Coordinator
Jun 25, 2014 at 2:23 AM
Hi Matt,

The http_client tutorial is actually quite short code wise and basically just walks through setting up the C++ Rest SDK and making a simple HTTP GET request. It sounds like that is what you want to do as well. I think you just need to create a http_client for the base portion of your URI and then make each of the requests and then decide what to do with the data. Probably looking something like this:
    uri address(U("http://10.180.90.171:8080/api/"));
    http_client client(address);
    std::vector<pplx::task<void>> requests;

    // Function=Cut
    requests.push_back(client.request(methods::GET, uri_builder(address).append_query(U("Function"), U("Cut")).to_string())
        .then([](http_response response)
    {
        // TODO check response.status_code() and handle any data...
    }));

    // Function=Fade
    requests.push_back(client.request(methods::GET, uri_builder(address).append_query(U("Function"), U("Fade")).to_string())
        .then([](http_response response)
    {
        // TODO check response.status_code() and handle any data...
    }));

    // Function=Zoom
    requests.push_back(client.request(methods::GET, uri_builder(address).append_query(U("Function"), U("Zoom")).to_string())
        .then([](http_response response)
    {
        // TODO check response.status_code() and handle any data...
    }));

    // Wait for all the requests to be processed and handle any exceptions.
    ::pplx::when_all(requests.begin(), requests.end()).then([](::pplx::task<void> t)
    {
        try
        {
            t.get();
        }
        catch (const http_exception &e)
        {
            // TODO handle exceptions...
        }
    });
Steve