Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::RestServer Class Reference

HTTP REST server implementation. More...

#include <mitkRestServer.h>

Inheritance diagram for mitk::RestServer:
Collaboration diagram for mitk::RestServer:

Public Member Functions

 RestServer ()
 
 ~RestServer () override
 
 RestServer (const RestServer &)=delete
 
RestServer & operator= (const RestServer &)=delete
 
 RestServer (RestServer &&)=delete
 
RestServer & operator= (RestServer &&)=delete
 
bool Start () override
 Start the REST server with the pending configuration. More...
 
void Stop () override
 Stop the REST server. More...
 
bool IsRunning () const override
 Check if the server is currently running. More...
 
void SetConfig (const RestServerConfig &config) override
 Set the pending server configuration. More...
 
RestServerConfig GetPendingConfig () const override
 Get the pending server configuration. More...
 
std::optional< RestServerConfig > GetRunningConfig () const override
 Get the configuration the server is currently running with. More...
 
void SetDataStorage (DataStorage *dataStorage) override
 Set the DataStorage for REST API operations. More...
 
DataStorage::Pointer GetDataStorage () const override
 Get the currently connected DataStorage. More...
 
void SetDispatcher (StorageThreadDispatcherBase *dispatcher)
 Set the thread dispatcher for DataStorage operations. More...
 
RenderWindowBridge * GetRenderWindowBridge () override
 Return the server-owned RenderWindowBridge. More...
 
std::optional< std::string > GetServerUrl () const override
 Get the full URL where the server is listening. More...
 
std::optional< std::string > GetLastError () const override
 Get the last error message. More...
 
std::vector< std::string > GetClientIPs () const override
 Get the list of client IP addresses that have sent requests. More...
 
std::optional< RequestInfo > GetLastRequestInfo () const override
 Get information about the last request processed. More...
 
void SetLogLimit (std::optional< unsigned int > limit) override
 Set the request log limit. More...
 
std::optional< unsigned int > GetLogLimit () const override
 Get the current request log limit. More...
 
std::vector< RequestInfo > GetRequestLog () const override
 Get all logged requests. More...
 
void ClearRequestLog () override
 Clear all logged requests. More...
 
uint64_t GetRequestLogVersion () const override
 Get the request log version counter. More...
 
std::optional< int64_t > GetUptimeSeconds () const override
 Get the server uptime in seconds. More...
 
- Public Member Functions inherited from mitk::IRestServerService
virtual ~IRestServerService ()
 

Detailed Description

HTTP REST server implementation.

Manages cpp-httplib server lifecycle and routes requests to appropriate controllers.

Definition at line 53 of file mitkRestServer.h.

Constructor & Destructor Documentation

◆ RestServer() [1/3]

mitk::RestServer::RestServer ( )

◆ ~RestServer()

mitk::RestServer::~RestServer ( )
override

◆ RestServer() [2/3]

mitk::RestServer::RestServer ( const RestServer &  )
delete

◆ RestServer() [3/3]

mitk::RestServer::RestServer ( RestServer &&  )
delete

Member Function Documentation

◆ ClearRequestLog()

void mitk::RestServer::ClearRequestLog ( )
overridevirtual

Clear all logged requests.

Implements mitk::IRestServerService.

◆ GetClientIPs()

std::vector<std::string> mitk::RestServer::GetClientIPs ( ) const
overridevirtual

Get the list of client IP addresses that have sent requests.

Returns a list of unique IP addresses from clients that have made requests to the server since it was started.

Returns
Vector of client IP addresses, empty if no requests have been made.

Implements mitk::IRestServerService.

◆ GetDataStorage()

DataStorage::Pointer mitk::RestServer::GetDataStorage ( ) const
overridevirtual

Get the currently connected DataStorage.

Returns
The connected DataStorage, or nullptr if none.

Implements mitk::IRestServerService.

◆ GetLastError()

std::optional<std::string> mitk::RestServer::GetLastError ( ) const
overridevirtual

Get the last error message.

Returns
The last error message, or std::nullopt if no error occurred since last Start().

Implements mitk::IRestServerService.

◆ GetLastRequestInfo()

std::optional<RequestInfo> mitk::RestServer::GetLastRequestInfo ( ) const
overridevirtual

Get information about the last request processed.

Returns
The last request info, or std::nullopt if no requests have been processed.

Implements mitk::IRestServerService.

◆ GetLogLimit()

std::optional<unsigned int> mitk::RestServer::GetLogLimit ( ) const
overridevirtual

Get the current request log limit.

Returns
The limit, or std::nullopt if unlimited.

Implements mitk::IRestServerService.

◆ GetPendingConfig()

RestServerConfig mitk::RestServer::GetPendingConfig ( ) const
overridevirtual

Get the pending server configuration.

This is the configuration that will be used on the next Start() call.

Returns
The pending configuration.

Implements mitk::IRestServerService.

◆ GetRenderWindowBridge()

RenderWindowBridge* mitk::RestServer::GetRenderWindowBridge ( )
overridevirtual

Return the server-owned RenderWindowBridge.

The bridge is owned by the server. UI-layer plugins (e.g. the Qt workbench plugin) configure it by setting callbacks for screenshot capture and crosshair position access. Callbacks must be cleared before the objects they reference are destroyed.

Returns
Pointer to the bridge. Never null.

Implements mitk::IRestServerService.

◆ GetRequestLog()

std::vector<RequestInfo> mitk::RestServer::GetRequestLog ( ) const
overridevirtual

Get all logged requests.

Returns the request log in chronological order (oldest first).

Returns
Vector of request info entries.

Implements mitk::IRestServerService.

◆ GetRequestLogVersion()

uint64_t mitk::RestServer::GetRequestLogVersion ( ) const
overridevirtual

Get the request log version counter.

Incremented on every log mutation (new entry, clear, trim). Allows consumers to detect changes without copying the full log.

Returns
Monotonically increasing version number.

Implements mitk::IRestServerService.

◆ GetRunningConfig()

std::optional<RestServerConfig> mitk::RestServer::GetRunningConfig ( ) const
overridevirtual

Get the configuration the server is currently running with.

Returns
The running configuration, or std::nullopt if server is not running.

Implements mitk::IRestServerService.

◆ GetServerUrl()

std::optional<std::string> mitk::RestServer::GetServerUrl ( ) const
overridevirtual

Get the full URL where the server is listening.

Returns
The server URL (e.g., "http://127.0.0.1:8080"), or std::nullopt if not running.

Implements mitk::IRestServerService.

◆ GetUptimeSeconds()

std::optional<int64_t> mitk::RestServer::GetUptimeSeconds ( ) const
overridevirtual

Get the server uptime in seconds.

Returns
Uptime in seconds, or std::nullopt if server is not running.

Implements mitk::IRestServerService.

◆ IsRunning()

bool mitk::RestServer::IsRunning ( ) const
overridevirtual

Check if the server is currently running.

Returns
true if the server is running, false otherwise.

Implements mitk::IRestServerService.

◆ operator=() [1/2]

RestServer& mitk::RestServer::operator= ( const RestServer &  )
delete

◆ operator=() [2/2]

RestServer& mitk::RestServer::operator= ( RestServer &&  )
delete

◆ SetConfig()

void mitk::RestServer::SetConfig ( const RestServerConfig &  config)
overridevirtual

Set the pending server configuration.

The configuration will take effect on the next Start() call. If the server is currently running, this only changes the pending config; the running config remains unchanged until Restart().

Parameters
configThe new configuration to use on next start.

Implements mitk::IRestServerService.

◆ SetDataStorage()

void mitk::RestServer::SetDataStorage ( DataStorage *  dataStorage)
overridevirtual

Set the DataStorage for REST API operations.

The server can operate without a DataStorage (graceful degradation), but data storage operations will return appropriate error responses. Can be called while the server is running.

Parameters
dataStorageThe DataStorage to use, or nullptr to disconnect.

Implements mitk::IRestServerService.

◆ SetDispatcher()

void mitk::RestServer::SetDispatcher ( StorageThreadDispatcherBase *  dispatcher)

Set the thread dispatcher for DataStorage operations.

Forwards to the internal DataStorageBridge. If set, all bridge operations are dispatched to the storage-owning thread.

Parameters
dispatcherThe dispatcher, or nullptr to clear.

◆ SetLogLimit()

void mitk::RestServer::SetLogLimit ( std::optional< unsigned int >  limit)
overridevirtual

Set the request log limit.

Controls how many request entries are kept in the log. The log is cleared when the server starts.

Parameters
limitMaximum number of entries to keep, or std::nullopt for unlimited.

Implements mitk::IRestServerService.

◆ Start()

bool mitk::RestServer::Start ( )
overridevirtual

Start the REST server with the pending configuration.

If the server is already running, this is a no-op and returns true. The pending configuration becomes the running configuration upon successful start.

Warning
Blocks until the server's listen loop is ready. Do not call it synchronously while a platform loader / plugin-activation lock is held: the blocking wait under that lock deadlocks. Defer the call onto the dispatch thread via StorageThreadDispatcherBase::Post() in that case.
Returns
true if the server started successfully (or was already running), false otherwise.

Implements mitk::IRestServerService.

◆ Stop()

void mitk::RestServer::Stop ( )
overridevirtual

Stop the REST server.

Blocks until the server is fully stopped. If the server is not running, this is a no-op.

Implements mitk::IRestServerService.


The documentation for this class was generated from the following file: