HttpServerPlugin for Unreal Engine 5 - a plugin that allows you to flexibly, quickly and easily configure a RESTful API server in an application on UE 5 using a config, to interact with it via http from the network. In the configs, you only need to define access points (endpoints), the request type (GET, POST etc.) and in the project code - redefine the response to these requests.
The connection algorithm is as follows:
- recommendations for joining new projects
- add to project dependency;
- set up the config;
- override request processing logic:
- known issues
Prof IT!
- Plugin repository: https://github.com/lpestl/HttpServerPlugin
The following methods are recommended for connecting to the project and reusing:
- To connect to a new project, it is recommended to connect this plugin to the repository as a git submodule. To do this, in the repository root (in the folder where the
*.uproject
file is located) of the project to which you want to connect this plugin, you need to run the following command:
git submodule add https://github.com/lpestl/HttpServerPlugin.git Plugins/HttpServerPlugin
This command will download the plugin repository and connect it as a submodule to the current project. By default, the latest stable version from the main branch will be downloaded.
- Download the latest stable version using one of the builds on the Releases page. Unzip the source archive to the
{project_path}/Plugins/
folder.
After that, it will be enough to regenerate the UE project and rebuild it in order to start using the connected plugin.
First, you need to make sure that the HttpServerPlugin
is included in the project. To do this, open the project in Unreal Editor, select the menu item Edit -> Plugins
, enter HttpServer
in the search and make sure that the box opposite the HttpServerPlugin
is checked.
The next step in the *.Build.cs
file is to add the HttpServerWrapperModule
module to the list of dependencies. For example:
The next step is to configure the module config file. This can be done using the UI: run the project in Unreal Editor and select Settings -> Project
Settings in the window that opens on the left, select the section called Plugins -> HTTP Server Settings
in the right part of the window, fill in the settings. For example:
After filling in the settings, the file {repo_path}/Config/DefaultHttpServer.ini
appears with approximately the following content:
[/Script/HttpServer.HttpServerSettings]
Port=8080
+Endpoints=(Endpoint="/get/data",Verbs=VERB_GET)
+Endpoints=(Endpoint="/add/data",Verbs=VERB_POST)
+Endpoints=(Endpoint="/update/data",Verbs=VERB_PUT)
+Endpoints=(Endpoint="/delete/data",Verbs=VERB_DELETE)
The main entity, which is a wrapper of the http server logic, is the UHttpServer
class, which is inherited from UObject
. To run a web server in your project, you can either create a blueprint and then create an object and use it, or create an object directly in the code.
- Creating and running the server:
- Stopping the server:
- Example of request processing:
Declare a pointer to UHttpServer
, for example by making it a class member:
private:
UPROPERTY(EditAnywhere)
UHttpServer* HttpServer;
};
Create a new class object:
HttpServer = NewObject<UHttpServer>();
Subscribe to the delegate that will be called when a request is received via http:
HttpServer->OnReceivedRequest().AddDynamic(this, &ASomeNewGameMode::OnReceivedRequest);
//...
}
void ASomeNewGameMode::OnReceivedRequest(const FString& RequestBody, FEndpointData EndpointData)
{
//...
}
And start the server:
HttpServer->StartApiServer();
In this case, you should not forget to stop the server in the appropriate place:
HttpServer->StopApiServer();
As an example:
#include "SomeNewGameMode.h"
#include "HttpServer.h"
void ASomeNewGameMode::BeginPlay()
{
Super::BeginPlay();
HttpServer = NewObject<UHttpServer>();
HttpServer->OnReceivedRequest().AddDynamic(this, &ASomeNewGameMode::OnReceivedRequest);
HttpServer->StartApiServer();
}
void ASomeNewGameMode::OnReceivedRequest(const FString& RequestBody, FEndpointData EndpointData)
{
//...
}
void ASomeNewGameMode::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
HttpServer->StopApiServer();
Super::EndPlay(EndPlayReason);
}
For full control over request processing and response sending, create your own class inherited from UHttpServer
and override the virtual function:
virtual bool HandleRequest(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete, FEndpointData EndpointData);
I connected the plugin to the project, configured everything, but I can’t reach the server API over the network.
The situation is quite typical: the server works locally, but does not accept connections by IP address from the network.
-
What's happening:
- 127.0.0.1:8080 works — this is a local loopback. The server listens only for local connections.
- 192.168.0.15:8080 (as exapmle) does not work — because the server does not listen to the external interface (IP network address).
-
Solution:
In the project, in the Config
folder, find and edit the DefaultEngine.ini
file, adding the following section to the end of the file, thereby indicating to the engine that the server should be made available for external connections over the network:
[HTTPServer.Listeners]
DefaultBindAddress=0.0.0.0
In Unreal Engine 5 (including 5.5), the HttpServerModule
does not support HTTPS by default (TLS/SSL) out of the box - it is intended only for a local or internal HTTP server and works exclusively over the HTTP protocol.