Jump to content

Recommended Posts

Anyone managed to call the "RestAPI" class GET/POST methods successfully?

I've been messing around trying to get a hello world type example working, but everytime I call the GET method the workbench crashes.
If someone has managed to get this working I'd love to see an example.
 

Maybe I'm just missing the obvious, so I'll include my test code below.

class PY_TestGameModeClass: SCR_BaseGameModeClass
{
};

class PY_RestCallback : RestCallback
{
	override void OnSuccess( string data, int dataSize )
	{
		Print(data);
		// JsonApiStruct json = new JsonApiStruct;
		// json.ExpandFromRAW(data);
		SCR_HintManagerComponent.GetInstance().ShowCustomHint(data, "Cat Factz!", 20.0);
	};
	
	override void OnError( int errorCode )
	{
		Print(" !!! OnError() ");
	};
};

class PY_TestGameMode: SCR_BaseGameMode
{
	
	override protected void EOnInit(IEntity owner)
	{
		super.EOnInit(owner);
		
		if(!System.IsConsoleApp()) //No GUI, so no events for it
		{
			Event_OnControllableSpawned.Insert(OnPlayerSpawnedClient);
		}
	}
	
	static PY_TestGameMode GetInstance()
	{
		return PY_TestGameMode.Cast(GetGame().GetGameMode());
	}
	
	void OnPlayerSpawnedClient(IEntity entity)
	{
		GetGame().GetCallqueue().CallLater(ShowCatFact, 5000);
	}
	
	void ShowCatFact()
	{
		PY_RestCallback cbx1 = new PY_RestCallback;
		RestContext ctx = GetGame().GetRestApi().GetContext("https://catfact.ninja/");
		ctx.GET(cbx1,"fact");
	}
}

 

Share this post


Link to post
Share on other sites

For anyone that ends up finding this thread, this issue seems to have been fixed in the latest patch (7th June).
The code I was testing is now returning as expected, without crashing the Enfusion workbench.

  • Like 3

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×