RestApiGet and LUA Scripting in Orthanc

Hello everyone,

I’m working on a LUA script that utilizes RestApiGet(uri) to retrieve data from a Postgres database, which is accessed via an API hosted on another container on the same server.

I am able to successfully retrieve the data using Postman, confirming that the API for Postgres is functioning correctly. However, it seems that RestApiGet is designed to communicate only with Orthanc’s own uri. When I attempt to use it to access the Postgres API, I encounter an issue related to the uri.

Can anyone confirm if RestApiGet and RestApiPost are indeed limited to Orthanc URIs only?

If that’s the case, I attempted to install the Requests library for Lua using the following Dockerfile:

FROM jodogne/orthanc:1.12.3
COPY ./orthanc_01/usr_local_share_orthanc_plugins/. /usr/local/share/orthanc/plugins/

Install necessary packages

RUN apt update && apt upgrade -y
RUN apt install -y libssl-dev
RUN apt install -y lua5.3 luarocks lua5.3-dev
RUN luarocks --lua-version=5.3 install lua-requests
RUN luarocks --lua-version=5.3 install luasocket

However, I’m facing the following error:

W0831 05:56:14.267875 LUA-HEARTBEAT LuaContext.cpp:94] Lua says: Lua version: Lua 5.3
W0831 05:56:14.267942 LUA-HEARTBEAT LuaContext.cpp:94] Lua says: Lua version: Lua 5.3
E0831 05:56:14.270928 LUA-HEARTBEAT OrthancException.cpp:61] Cannot execute a Lua command: error loading module ‘socket.core’ from file ‘/usr/local/lib/lua/5.3/socket/core.so’:
/usr/local/lib/lua/5.3/socket/core.so: undefined symbol: lua_gettop
terminate called after throwing an instance of ‘Orthanc::OrthancException’

Does anyone have any suggestions on how to resolve this issue?
Many thanks!

Hello,

Yes, RestApiGet() and RestApiPost() provide a direct access to the REST API of Orthanc, and only to that REST API, as explained in the documentation.

If you want to do a request to an arbitrary URL, just use the built-in HttpGet() and HttpPost() Lua functions. They are also described in the documentation.

Finally, note that Orthanc comes with its embedded Lua interpreter. In general, you should not try to load external Lua modules such as lua-requests. However, there exist hacks to do so, and this topic is also covered in the documentation.

In general, for advanced use cases, you should use the Python plugin for Orthanc instead of Lua.

Regards,
Sébastien-

Hi Sébastien,
It worked! the documentation is very clear… well done!
And appreciated your fast response during your weekend!

1 Like