Calling external APIs

Discussion in 'Javascript/Plugin Support' started by wizaerd, Oct 27, 2015.

  1. wizaerd

    wizaerd Adventurer Member

    Messages:
    219
    Likes Received:
    26
    First Language:
    English
    Is it possible to use AJAX to call a RESTful service from within our game? Either HttpGet or HttpPost?
     
    #1
    Hudell likes this.
  2. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,323
    Likes Received:
    2,969
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Yup, with XmlHttpRequest
     
    #2
  3. wizaerd

    wizaerd Adventurer Member

    Messages:
    219
    Likes Received:
    26
    First Language:
    English
    So it's available from within the Engine?  And it'd be callable just like any AJAX call on a webpage would?
     
    #3
    Hudell likes this.
  4. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,323
    Likes Received:
    2,969
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Yes.
    I only tested it while running the game from chrome, but I assume it would work the same way with the windows exe.
     
    #4
  5. altorn

    altorn Veteran Veteran

    Messages:
    53
    Likes Received:
    12
    Location:
    Toronto, Canada
    First Language:
    English
    I thought cross domain XHR doesn't work? I guess I'm wrong. lol
     
    #5
  6. wizaerd

    wizaerd Adventurer Member

    Messages:
    219
    Likes Received:
    26
    First Language:
    English
    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.
     
    #6
  7. harvard1932

    harvard1932 Veteran Veteran

    Messages:
    40
    Likes Received:
    10
    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 *
     
    #7
  8. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,071
    Location:
    Toronto
    First Language:
    English
    Why would it be a challenge to "access" someone else's server?


    By "access" do you mean something other than sending a request?
     
    #8
  9. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,323
    Likes Received:
    2,969
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Servers usually reject ajax requests that comes from a different domain.
     
    #9
  10. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,071
    Location:
    Toronto
    First Language:
    English
    I was confusing AJAX with a simple RESTful implementation, where client queries some server through an API and then you just handle the response.
     
    #10

Share This Page