UE4 HTTP Response on BlueprintCallable and Delegates

Hello everyone. I’m trying to do http request and response on c++ as blueprintcallable. But I couldn’t handle the delegates. I cannot access HTTP Response after binding OnResponseRecieved function. How can I access my HTTP Response on blueprintcallable. I couldn’t succeed on Multicast delegates.If you think Multicast Delegates is the best option for this. Can you help me with that. here is my codes

MyBlueprintFunctionLibrary.h

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "Runtime/Core/Public/Delegates/Delegate.h"
#include "MyBlueprintFunctionLibrary.generated.h"

/**
 * 
 */


UCLASS()
class TESTPLUGIN_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	FString ApiBaseUrl;
   
	UFUNCTION(BlueprintCallable, Category = "HTTP")
	static void SetBaseURL(FString BaseURL, FString& ApiBaseUrl);

	UFUNCTION(BlueprintCallable, Category = "HTTP")
	static void RequestCall(FString ApiBaseUrl, FString Subroute);

	static void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);

};

MyBlueprintFunctionLibrary.cpp

#include "MyBlueprintFunctionLibrary.h"
#include "Runtime/Json/Public/Json.h"
 
void UMyBlueprintFunctionLibrary::SetBaseURL(FString BaseURL, FString& ApiBaseUrl) {
	ApiBaseUrl = BaseURL;
	UE_LOG(LogTemp, Warning, TEXT("BaseURL is worked"));
}

void UMyBlueprintFunctionLibrary::RequestCall(FString ApiBaseUrl, FString Subroute) {
	FHttpModule* Http = &FHttpModule::Get();
	TSharedRef<IHttpRequest> Request = Http->CreateRequest();
	UE_LOG(LogTemp, Warning, TEXT("Request is worked"));
	FScriptDelegate Delegate;
	Request->OnProcessRequestComplete().BindStatic(UMyBlueprintFunctionLibrary::OnResponseReceived);
	Request->SetURL(ApiBaseUrl + Subroute);
	Request->SetHeader(TEXT("User-Agent"), TEXT("X-UnrealEngine-Agent"));
	Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
	Request->SetHeader(TEXT("Accepts"), TEXT("application/json"));
	Request->ProcessRequest();
}

/*Assigned function on successfull http call*/
void UMyBlueprintFunctionLibrary::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
	UE_LOG(LogTemp, Warning, TEXT("OnResponseReceived function is ready!!"));
	//Create a pointer to hold the json serialized data
	TSharedPtr<FJsonObject> JsonObject;

	//Create a reader pointer to read the json data
	TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
	//Deserialize the json data given Reader and the actual object to deserialize
	if (FJsonSerializer::Deserialize(Reader, JsonObject))
	{
		//Get the value of the json object by field name
		int32 recievedInt = JsonObject->GetIntegerField("userId");

		//Output it to the engine
		UE_LOG(LogTemp, Warning, TEXT("Response is coming xP"));
		UE_LOG(LogTemp, Warning, TEXT("Id is: %d"), recievedInt);
	}
}

I would love to do something very similar, so if anyone could help, that would be great.

This is an old post now, but for anyone who comes across it looking for something similar; the easiest way to deal with it is to use

This is an old post now, but for anyone who comes across it looking for something similar; the easiest way to deal with it is to use BindLambda instead of BindStatic. Then you can pass the callback directly to the lambda function.

Here is the simplest example I can think of, which takes a callback function in blueprints and calls it when the request goes through. You can of course add JSON handling and all that to the lambda function.

MyBlueprintFunctionLibrary.h

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "HttpFunctionLibrary.generated.h"


DECLARE_DYNAMIC_DELEGATE_ThreeParams(FHttpRequestResponse, FString, ResponseString, int, HttpStatus, bool, Success);

/**
 * 
 */
UCLASS()
class HTTPTESTING_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

	UFUNCTION(BlueprintCallable)
	static void GetRequest(FString URL, FHttpRequestResponse Callback);
	
};

MyBlueprintFunctionLibrary.cpp

#include "MyBlueprintFunctionLibrary.h"

#include "HttpModule.h"
#include "Interfaces/IHttpResponse.h"

void UMyBlueprintFunctionLibrary::GetRequest(FString URL, FHttpRequestResponse Callback)
{
	auto Http = &FHttpModule::Get();

	FHttpRequestPtr Request = Http->CreateRequest();
	Request->SetURL(URL);
	Request->SetVerb("GET");
	Request->OnProcessRequestComplete().BindLambda([Callback](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
	{
		Callback.ExecuteIfBound(Response->GetContentAsString(), Response->GetResponseCode(), bWasSuccessful);
	});
	Request->ProcessRequest();
}

The other way of doing it would be to use UObjects instead, and bind to UObject functions. There are examples of how to do it here: GitHub - nsjames/UE4_Tutorial_Http: Proper usage of HTTP within UE4

About HTTP response on BlueprintCallable and Delegates, maybe get some inspiration from this plugin: