Page MenuHomeFeedback Tracker

Rest API "_now" is not working without created RestCallback
Assigned, NormalPublic

Description

Issue: Any Rest API function will not work without RestCallback created.

I ran into an unusual problem when trying to get response data from GET request from my back-end server and from any other site/server. After several hours of debugging, I found solution to my problem, but as I understand it, this is a bug. Without creating callback (new RestCallback()), none of the Rest API functions work, even the _now functions that do not require a callback.
Here are two examples in which I am using my back-end server and the site http://checkip.amazonaws.com/ :

// My RestCallBack class for testing Rest Api

class TestCallBack : RestCallback
{
        override void OnError( int errorCode )
        {
        Print("OnError");
	};

	override void OnTimeout()
	{
        Print("OnTimeout");
	};

	override void OnSuccess( string data, int dataSize )
	{
        Print("OnSuccess");
	};

	override void OnFileCreated( string fileName, int dataSize )
	{
        Print("OnFileCreated");
	};
}
// Rest Api Script Without created RestCallBack

void GetRestApiFunction()
    {
        string amazonContext = "http://checkip.amazonaws.com/";
        string backEndContext = "http://localhost:5001/api/Database/";
        
        RestContext m_apiAmazonRestContext = GetGame().GetRestApi().GetContext(amazonContext);
        RestContext m_apiBackEndRestContext = GetGame().GetRestApi().GetContext(backEndContext);
		
        // _now Requests
        Print("checkip.amazonaws response: " + m_apiAmazonRestContext.GET_now(""));
        Print("back-end server response: " + m_apiBackEndRestContext.GET_now("1"));

        // GET Requests
        m_apiAmazonRestContext.GET(new TestCallBack(), "");
        m_apiBackEndRestContext.GET(new TestCallBack(), "1");
    }

// Log Console:
  SCRIPT       : checkip.amazonaws response: 
  SCRIPT       : back-end server response: 

// My back-end server console log:
INFO: GET REQUEST CAME

Now test with new RestCallback() :

// Rest Api Script Without created RestCallBack

ref TestCallBack callback;

    void GetRestApiFunction()
    {
	string amazonContext = "http://checkip.amazonaws.com/";
        string backEndContext = "http://localhost:5001/api/Database/";
        
        callback = new TestCallBack();

        RestContext m_apiAmazonRestContext = GetGame().GetRestApi().GetContext(amazonContext);
        RestContext m_apiBackEndRestContext = GetGame().GetRestApi().GetContext(backEndContext);
		
        // _now Requests
        Print("checkip.amazonaws response: " + m_apiAmazonRestContext.GET_now(""));
        Print("back-end server response: " + m_apiBackEndRestContext.GET_now("1"));

        // GET Requests
        m_apiAmazonRestContext.GET(callback, "");
        m_apiBackEndRestContext.GET(callback, "1");
    }

// Log Console:
  SCRIPT       : checkip.amazonaws response: 123.456.789.123         // ofc its not my ip, but i got right response
  SCRIPT       : back-end server response: im alive?
  SCRIPT       : OnSuccess
  SCRIPT       : OnSuccess

// My back-end server console log:
INFO: GET REQUEST CAME

The main problem is that _now functions don't work without a callback created, even if they don't use them / don't need them.

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 11 x64
Operating System Version
22H2
Category
General

Event Timeline

Geez changed the task status from New to Assigned.Aug 31 2023, 11:24 AM