MetaRest is an advanced plugin for Unreal Engine 5, designed to simplify REST server communications by exposing HTTP requests directly to Blueprints. This powerful tool allows developers to seamlessly integrate RESTful APIs into their projects without the need for C++ coding knowledge or creating C++ projects. It provides a reliable and efficient solution for connecting to REST APIs within Unreal Engine.
Technical Details
List of Modules:
- MetaRest (Runtime): Offers runtime functionality for smooth and efficient HTTP/HTTPS communication within Unreal Engine projects.
List of Features:
- Advanced HTTP/HTTPS Request Management: Supports a wide range of HTTP verbs (e.g., GET, POST, PUT, DELETE) and various content types, enabling robust and flexible server interactions.
- No C++ Coding Required: Fully accessible through Unreal Engine Blueprints, making it user-friendly and approachable for developers of all experience levels.
- Comprehensive JSON Handling with Blueprint Support: Features a blueprint-compatible
FJsonObject
wrapper, supporting almost all JSON functionalities. Developers can manage diverse value types, arrays, binary data, and perform bidirectional serialization withFString
. - Blueprintable JSON Value Wrapper: Includes a
FJsonValue
wrapper, bringing complete JSON manipulation capabilities into Blueprints, allowing seamless handling of JSON data. - Asynchronous Request Handling: Offers bindable events and latent functions to manage asynchronous requests, ensuring smooth and efficient integration into any project.
Supported Platforms:
- MetaRest is designed to operate on Windows, providing a reliable solution for Unreal Engine projects on this platform.
Tested Platforms:
- The plugin has been thoroughly tested and optimized for Windows, ensuring stability and high performance.
Part of the Meta System
MetaRest is an integral part of the Meta System, a comprehensive suite of tools designed to enhance Unreal Engine projects. The MetaOnlineSubsystem relies on the MetaRest plugin to enable seamless communication with RESTful APIs, ensuring reliable and efficient online functionality.
MetaRest Subsystem
The MetaRest Subsystem is the core component of the MetaRest plugin, designed to provide seamless integration of REST API communications within Unreal Engine projects. Acting as a centralized system, it enables developers to manage HTTP/HTTPS requests and responses efficiently and supports advanced features that simplify interaction with web services.
Functionality
The MetaRest Subsystem is responsible for:
- Handling REST API Communications: Acts as the foundation for sending and receiving HTTP requests, ensuring all data exchanges between the game and external servers are managed effectively.
- Blueprint Integration: Provides Blueprint-accessible nodes to enable easy integration of RESTful API calls without requiring C++ knowledge.
- Asynchronous Processing: Supports asynchronous request handling, ensuring that game performance is not interrupted while waiting for server responses.
- Global Access: As a subsystem, it can be accessed from anywhere in your project, streamlining the workflow for managing REST API requests.
Key Features
Centralized Request Management:
- The MetaRest Subsystem acts as a centralized point for all REST-related operations, reducing the need for multiple instances and improving consistency across the project.Blueprint Accessibility:
- Fully integrated into Unreal Engine’s Blueprint system, allowing developers to implement REST API functionality without coding in C++.High Customizability:
- Configurable HTTP methods, headers, and payloads.
- Flexible JSON serialization and deserialization, enabling interaction with complex data structures.Scalability:
- Suitable for small to large-scale projects that require REST API communication, including multiplayer games, analytics integration, and external service connections.Error Handling and Callbacks:
- Built-in support for managing errors and asynchronous callbacks to handle responses in real time.
Use Cases
- Authentication Systems: Send user credentials to a server for login or token validation.
- Leaderboard and Statistics: Retrieve and update player stats from an external database.
- Game Data Syncing: Fetch game settings or dynamic content from a REST API.
- Third-Party Integration: Integrate analytics, payment gateways, or other web services into your game.
Why Use the MetaRest Subsystem?
The MetaRest Subsystem simplifies the traditionally complex task of managing REST API communications in Unreal Engine. By providing a robust and accessible interface for handling HTTP requests and responses, it empowers developers to focus on game logic while ensuring seamless server communication. Whether your project involves simple API calls or complex web service integrations, the MetaRest Subsystem is a reliable and efficient tool for achieving your goals.
Functions Overview
Function: Call URL
The Call URL
function in the MetaRest plugin is a Blueprint-exposed method that enables seamless communication with REST APIs via HTTP requests. This function simplifies the process of interacting with web services directly within Unreal Engine, allowing developers to send and receive data asynchronously.
Function Details:
Inputs:
Target (
Object Reference
):
- Specifies the calling object. Typically, this is set toMeta Rest Subsystem
, representing the current Blueprint or class using the function.URL (
String
):
- The endpoint URL of the REST API you want to communicate with. This is where the request will be sent.
- Example:http://127.0.0.1:8000/
Verb (
Dropdown
):
- Defines the HTTP method (verb) to use for the request.
- Options include:GET
POST
PUT
DELETE
- Example:
POST
is commonly used for sending data to the server.
Content Type (
Dropdown
):
- Specifies the format of the request payload or body.
- Common options include:application/json
(for JSON data)x-www-form-urlencoded
(for form-encoded data)- Example:
x-www-form-urlencoded
is suitable for sending simple key-value pairs.
Meta Rest JSON (
Asset Reference
):
- A reference to a JSON asset containing the data payload for the request. This asset can be created and managed within Unreal Engine, allowing structured data to be sent to the server.Callback (
Execution Pin
):
- Used to handle the response of the HTTP request asynchronously. The callback pin allows developers to execute logic after receiving the server's response.
Outputs:
- The function does not directly return a value but instead executes the callback once the request is complete. This ensures that all responses, including errors, can be handled programmatically in Blueprints.
Use Case Example:
Authentication Request:
- URL:http://127.0.0.1:8000/
- Verb:POST
- Content Type:x-www-form-urlencoded
- JSON Payload: Includes user credentials (e.g., username and password).
- Callback: Processes the authentication response and executes actions based on success or failure.Retrieving Data:
- Verb:GET
- URL: Points to an API endpoint providing data (e.g., player stats).
- No JSON payload is required forGET
requests.
Construct JSON Object Function
The Construct JSON Object
function in the MetaRest Subsystem is a Blueprint-exposed utility designed to create and manipulate JSON objects dynamically. It allows developers to build structured data directly within Unreal Engine Blueprints, which can then be sent as a payload in REST API requests.
Functionality
The Construct JSON Object
function is used to:
1. Initialize a JSON Object:
- Creates a new, empty JSON object that can store key-value pairs of various data types such as strings, integers, booleans, and more.
Add Fields to the JSON Object:
- Fields can be added to the JSON object using various "Set Field" nodes like:Set Number Field
: Adds a numeric value.Set Integer Field
: Adds an integer value.Set Int 64 Field
: Adds a 64-bit integer value.Set Bool Field
: Adds a boolean value (true/false).Set String Field
: Adds a string value.- Each field requires a
Field Name
(key) and its corresponding value.
Construct Complex JSON Structures:
- Allows the combination of different data types to create nested or complex JSON structures suitable for REST API requests.
Inputs:
- Target (MetaRest Subsystem):
- The target reference, which is typically the
Meta Rest Subsystem
. It acts as the controller for the JSON operations.
Outputs:
- Return Value (JSON Object Reference):
- The constructed JSON object, which can be passed to other functions, such as
Call URL
, to serve as the body of an HTTP request.
Workflow Example:
Step 1: Initialize JSON Object
- Use theConstruct JSON Object
node to create an empty JSON object.Step 2: Add Fields
- Use the following nodes to add data:Set Number Field
: Add a floating-point value (e.g., "price": 19.99).Set Integer Field
: Add an integer value (e.g., "quantity": 5).Set Bool Field
: Add a boolean value (e.g., "isAvailable": true).Set String Field
: Add a string value (e.g., "productName": "Widget").
Step 3: Send JSON in REST API Request
- Pass the constructed JSON object as a parameter to theCall URL
node to include it as the payload in an HTTP request.
Benefits:
- Dynamic JSON Construction: Easily create JSON objects with varying structures during runtime.
- No C++ Required: Fully accessible within Blueprints for non-programmers.
- REST API Integration: Works seamlessly with
Call URL
to handle RESTful API requests.
Example Blueprint Flow Explanation
This blueprint demonstrates the complete process of creating a JSON object, populating it with fields, and sending it as a payload in a REST API request using the MetaRest Subsystem. Each step in the flow contributes to constructing and sending a well-formed request to a RESTful API.
Step-by-Step Breakdown
1. MetaRest Subsystem Initialization
- The
Meta Rest Subsystem
node acts as the central controller, allowing you to create and manage JSON objects and handle REST API calls.
2. Construct JSON Object
- The
Construct JSON Object
node creates a new, empty JSON object that will serve as the payload for the API request.
3. Set Fields in the JSON Object
- Various
Set Field
nodes populate the JSON object with data. Each field is defined by: - Field Name: The key for the JSON object.
- Value: The corresponding value for the key. Different nodes handle specific data types:
Set Number Field
: Adds a floating-point value (e.g.,"price": 19.99
).Set Integer Field
: Adds an integer value (e.g.,"quantity": 5
).Set Bool Field
: Adds a boolean value (e.g.,"isAvailable": true
).Set String Field
: Adds a string value (e.g.,"productName": "Widget"
).
4. Call URL
- The
Call URL
node sends the constructed JSON object as the body of a REST API request. - URL: Specifies the API endpoint (e.g.,
http://127.0.0.1:8000/product/api/
). - Verb: The HTTP method (e.g.,
POST
). - Content Type: Defines the format of the request payload (
x-www-form-urlencoded
in this case). - Meta Rest JSON: Connects the previously constructed JSON object to be sent in the request body.
- Callback: A pin that executes after the request is completed, triggering further actions.
5. Request Completed
- The
RequestCompleted
custom event handles the server's response. This can include: - Parsing the response data.
- Checking for errors or success codes.
- Updating the game state or UI based on the server's response.
Example Payload
The constructed JSON payload sent to the server in this example would look like this:
{
"price": 19.99,
"quantity": 5,
"isAvailable": true,
"productName": "Widget"
}
Use Case
This flow could be used to:
- Submit product details to an inventory management system.
- Send player statistics or settings to a server.
- Create dynamic API requests based on in-game actions or player input.
Key Benefits of This Flow
- Dynamic JSON Construction: JSON payloads are built on-the-fly based on Blueprint logic.
- REST API Integration: Seamless connection to external web services or databases.
- Blueprint-Friendly: No C++ coding required, making it accessible to all Unreal Engine developers.
- Asynchronous Handling: Ensures smooth gameplay while waiting for the server’s response.