Calling external APIs

● ARCHIVED · READ-ONLY
Started by wizaerd 10 posts View original ↗
  1. Is it possible to use AJAX to call a RESTful service from within our game? Either HttpGet or HttpPost?
  2. Yup, with XmlHttpRequest
  3. Hudell said:
    Yup, with XmlHttpRequest
    So it's available from within the Engine?  And it'd be callable just like any AJAX call on a webpage would?
  4. wizaerd said:
    So it's available from within the Engine?  And it'd be callable just like any AJAX call on a webpage would?
    Yes.
    I only tested it while running the game from chrome, but I assume it would work the same way with the windows exe.
  5. I thought cross domain XHR doesn't work? I guess I'm wrong. lol
  6. If using Chrome, adding in an "Access-Control-Allow-Origin" HTTP header to all out-going responses from the server eliminates this... It also allows for the file:// protocol to work as well for testing stuff locally.  Of course, this wuld mean you'd have to create your own service in order to add this response header, but that's easy enough to do with C# and WebAPI.  Accessing someone else's server though... There'd be a challenge.
  7. hue... it is not even hard to cross site :p

    http://game.darkkyshadow.com/dashboard/

    uses cross site scripts from

    www.darkkyshadow.com

    all you have to do is to set Access-Control-Allow-Origin flag 

    For people who are lazy, there is chrome plugin that disables Access-Control-Allow-Origin entirely. Making all websites Access-Control-Allow-Origin *
  8. wizaerd said:
    If using Chrome, adding in an "Access-Control-Allow-Origin" HTTP header to all out-going responses from the server eliminates this... It also allows for the file:// protocol to work as well for testing stuff locally.  Of course, this wuld mean you'd have to create your own service in order to add this response header, but that's easy enough to do with C# and WebAPI.  Accessing someone else's server though... There'd be a challenge.
    Why would it be a challenge to "access" someone else's server?


    By "access" do you mean something other than sending a request?
  9. Tsukihime said:
    Why would it be a challenge to "access" someone else's server?

    By "access" do you mean something other than sending a request?
    Servers usually reject ajax requests that comes from a different domain.
  10. Hudell said:
    Servers usually reject ajax requests that comes from a different domain.
    I was confusing AJAX with a simple RESTful implementation, where client queries some server through an API and then you just handle the response.