Medical Imaging Interaction Toolkit
2024.06.00
Medical Imaging Interaction Toolkit
|
The MITK REST Module is able to manage REST requests. The main class is the RESTManager. It is a MicroServices which can be accessed via
The module uses the Microsoft C++ REST SDK for REST mechanisms as well as JSON conversion and asynchronic programming.
You can use the REST module from two different perspectives in MITK:
The following sections will give you an introduction on how to use which of those roles:
To act as a server, you need to implement the IRESTObserver
, which has a Notify()
method that has to be implemented. In this Notify()
method you specify how you want to react to incoming requests and with which data you want to respond to the requests.
You can then start listening for requests from clients as shown below:
If a client sends a request, the Notify method is called and a response is sent. By now, only GET-requests from clients are supported.
If you want to stop listening for requests you can do this by calling
You don't have to specify a uri in the HandleDeleteObserver method, if you only call managerService->HandleDeleteObserver(this);
, all uris you receive requests for are deleted and you aren't listening to any requests anymore.
The following example shows how to send requests from a client perspective:
The steps you need to make are the following:
us::ModuleRegistry
. SendRequest
method. This will start the request itself and is performed asynchronously. As soon as the response is sent by the server, the .then(...)
block is executed. .then(...)
block. For exception handling, it is important to choose pplx::task<web::json::value>
. This is a task-based continuation. For more information, visit https://docs.microsoft.com/en-us/cpp/parallel/concrt/exception-handling-in-the-concurrency-runtime?view=vs-2017. .get()
. At this point, an exception is thrown if something in the previous tasks threw an exception. .then(...)
block, you need to do this by using signals and slots because GUI elements can only be modified by th Qt Main Thread. For more information, visit https://doc.qt.io/qt-6/thread-basics.html#gui-thread-and-worker-thread Code, which is followed by this codeblock shown above will be performed asynchronously while waiting for the result. Besides Get-Requests, you can also perform Put or Post requests by specifying a RequestType
in the SendRequest
method.
The following example shows, how you can perform multiple tasks, encapsulated to one joined task. The steps are based on the example for one request and only the specific steps for encapsulation are described.
The steps you need to make are the following:
then(...)
of the joinTask is performed when all single tasks are finished.