In this post we’re going to see how to use the http module that is built inside the engine to perform http calls to various APIs. We’re going to perform a basic http call without sending any data, however I have commented out the code that you can use in order to send simple data (eg strings) or even data in the form of a json file type.

Download the entire source code from my GitHub repo

Adding the required Dependencies

For this post I have created a project using the 4.20 version of the engine. Then, I added the Http module as a dependency in the public module names in my <MyProject>.build.cs file:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "HTTP" });

Performing the http request

The http module offers an straightforward way to both perform http calls as well as react to the answer of the server. Having said that, I have created two functions in my header file, one for performing a request and one function that fires when our request has been processed (meaning the server has responded):

Here’s the implementation of both functions:

For my testing, in the Url link I used my GitHub’s username (ie https://api.github.com/users/orfeasel ). Here’s the response of the server when I performed my call:

(Click on image to enlarge in a new tab)

As you can see the response is really a json file. In case you would like to consume the retrieved data check out my tutorial on Json Parsing.

(The reason that my OnResponse event fired twice is because I performed two requests)