Calling an HTTP request from a function

Jul 23, 2014 at 5:45 PM
Hi All,

Just a quick question. Right now I'm using a video editing software that has an API using HTTP protocol. To perform the request I want, all the code i need is the following:
http_client client(L"");
    return client.request(methods::GET).then([](http_response response)
(where "NUMBER" is an integer of some kind)

I want to build a function, let's call it APICaller, that takes an integer input, and puts it in the location of "NUMBER", but can't figure out how to get an integer into the uri.

So basically, I'm going for something like this:
void APICaller( int NUMBER ) {
http_client client(L"");
    return client.request(methods::GET).then([](http_response response)
where "NUMBER" would change according to my input. Any ideas on how to accomplish this? Thank you!
Jul 23, 2014 at 6:19 PM
Hi mrm63,

you can use our web::uri_builder to create the uri.
void api_call(int number)
    web::uri_builder uribuilder(L"");

    uribuilder.append_query(L"Function", L"OverlayInput1");
    uribuilder.append_query(L"Input", number);

    auto uri = uribuilder.to_uri();
    http_client client(uri);
    client.request(methods::GET).then([](http_response response)
Aug 7, 2014 at 4:29 PM
Edited Aug 7, 2014 at 4:55 PM
Hi Zhelu:

Thanks for the response-- that was extraordinarily helpful! I do have one quick follow up if you don't mind!

How could I change this so that the user could input (or the program detect) the IP address of the computer. I'd like the api_call fxn still to only take the "number" input, but the IP address will change depending on what computer I run the .exe file on. So, I was hoping to figure out a way to have the IP address either be automatically detected, or as a user input in the command window. Any ideas?

For example, two computers I've used have been:


So either I need to figure out how to manually enter "" or "" in the command window, and then store that as a string or a variable, or ideally have the computer detect it.

It looks like the port stays the same with my particular software package, but the server doesn't. I want to be able to call the function as I did earlier, and have the program be able to construct the uribuilder as normal with my particular IP address. Does that make sense?