RESTAPI Testing

C++Friends - Code Plugins - Aug 19, 2024
1
4 out of 5 stars(1 rating)
  • 0%
  • 100%
  • 0%
  • 0%
  • 0%

Testing your RESTful API server in UE_5.3+

  • Supported Platforms
  • Supported Engine Versions
    5.3 - 5.4
  • Download Type
    Engine Plugin
    This product contains a code plugin, complete with pre-built binaries and all its source code that integrates with Unreal Engine, which can be installed to an engine version of your choice then enabled on a per-project basis.

This plugin provides 3 methods for testing REST API functionality.


RESTAPI Tester Plugin Manual


1. RESTAPI HJH Server Testing

This method tests the RESTAPI using a default server provided by the plugin.

  1. Create a new Blueprint in the Content Browser.
  2. In the Blueprint editor, search for the "RESTAPI HJH Server Testing" function when adding a node.
  3. Add this node to the graph and connect the execution pin.
  4. Input a float value as a parameter (this value is only output to the log and doesn't affect the server call).
  5. Compile and save the Blueprint.
  6. When you run the game or call the Blueprint in the editor, it will send a GET request to the default provided server (http://61.32.96.242:8000/howtotest/jjj).

Note: The default server is maintained to be available at all times, but there might be instances when it's unavailable.


2. Make REST API Call (Using a custom server)

This method allows you to test the RESTAPI with a server address of your choice.

  1. Create a new Blueprint in the Content Browser.
  2. In the Blueprint editor, search for the "Make REST API Call" function when adding a node.
  3. Add this node to the graph and connect the execution pin.
  4. Input two string parameters to the function:
  1. Compile and save the Blueprint.
  2. When you run the game or call the Blueprint in the editor, it will send a request to the specified URL using the specified HTTP method.


3. Send Message Async (Asynchronous POST request)

This method allows you to send an asynchronous POST request to a specified server and receive the response. It is compatible with Epic Games' JSON plugin on the market to convert JSON string from JSON Object.

  1. Create a new Blueprint in the Content Browser.
  2. In the Blueprint editor, search for the "Send Message Async" function when adding a node.
  3. Add this node to the graph and connect the execution pin.
  4. Input two string parameters to the function:
  • BaseUrl: The base URL of the server you want to send the message to (e.g., "http://your-server.com/api")
  • Message: The message you want to send
  1. Create a variable of type "Message Response" to store the output.
  2. Connect the "Out Response" pin from the "Send Message Async" node to your "Message Response" variable.
  3. Add a "Delay" node after the "Send Message Async" node to wait for the response (e.g., 1-2 seconds).
  4. After the delay, you can access the response data from your "Message Response" variable.
  5. Compile and save the Blueprint.

Here's an example of how your Blueprint might look


Output and Logging

All methods will output the server response to the log. In the output log, you can check the following information:

  • HTTP response code
  • Response content type
  • Response body
  • If the response is JSON, the parsed JSON fields

For the "Send Message Async" function, you can also access the response data directly in your Blueprint through the "Message Response" structure, which includes:

  • Success: A boolean indicating if the request was successful
  • Message: A string containing a message about the response (e.g., "JSON response received successfully")
  • JsonResponse: A structure containing the parsed JSON data as key-value pairs
This plugin is useful for quickly checking the status of RESTAPI servers and sending asynchronous requests. It can be particularly helpful when testing and debugging communication with servers during game development.

Technical Details

Features:

  • REST API call functionality supporting GET and POST methods
  • Customizable API server address
  • Simple interface accessible via Blueprints
  • HTTP request and response handling
  • Asynchronous request processing to minimize impact on game performance

Code Modules:

  • RESTAPI_Tester (Runtime Module): Runtime module providing REST API call functionality

Number of Blueprints: 3

Number of C++ Classes: 3


Network Replicated: No

Supported Development Platforms:

  • Windows 64-bit

Supported Target Build Platforms:

  • Windows 64-bit

Documentation: The plugin documentation can be found in the 'Documentation' folder within the plugin directory. It includes usage instructions and API references.

Important/Additional Notes:

  • This plugin is compatible with Unreal Engine 5.3 and above.
  • Currently supports Windows 64-bit platform only.
  • Use the MakeRestApiCall function to send GET or POST requests.