HTML Page Using Javascript to Access C++ REST Web Service?

Feb 22, 2016 at 3:45 PM
Hey All,

So I've spent about two weeks learning and creating my web service using C++ REST.

I've really liked it so far and I've actually got everything up and running I believe. Here is some of the code I am using which will process a simple GET request.
int main(int argc, char *argv[])

    uri_builder uri(L"http://localhost:8888");          // This defines my URI location. example is http://localhost:8888/
    http_listener listener(uri.to_uri());              //this will create a listener at the given location of my defined URI above
    printf("HTTP LISTENER STARTED \n");

    // This is the part where the listener can handle GET requests, [](http_request request)         // this block causes the listener to support GET requests
        {                              // When pinged for a GET request it will do the following
        printf("GET Request\n");    
        int status = 5;
        web::json::value statvalue = json::value::number(status);  //putting status into a json container
        printf("GET Request Finished \n");
        request.reply(status_codes::OK, statvalue);

This handles an incoming GET request and will output the value 5 if completed. I've tested this using TELNET to connect to the webservice and I used a generic GET request

GET /test HTTP/1.1
Host: localhost

in order to show that it all works out.

Now I am trying to create an HTML web page that will perform a GET request to my webservice.

So far I've been unable to perform this. Below is what my HTML page is looking like

    <title>GET TEST</title>
        <script language="JavaScript">
            var iCallID;
            function InitializeService()
                service.useService("http://localhost:8888/",  "httprequestservice");

            function ShowResult()
        <meta http-equiv="refresh" content="5" />

    <body  onload="InitializeService()"  id="service" style="behavior:url("  onresult="ShowResult()">
What am I doing wrong? Is there an example somewhere that someone could show me how to access this websebservice using an HTML page?

Feb 22, 2016 at 6:13 PM
My discussion is moved over here!