Question about "RestApiPostAfterPlugins()"

Was reading through some of the online documentation here:

https://book.orthanc-server.com/plugins/python.html#auto-routing-studies regarding the RestApiPostAfterPlugins(). Not sure that that is what I am interested in as it isn’t clear to me what that actually does.

Wondering if there is a way to register a callback that matches the built-in orthanc endpoint such that the python plug-in is executed first (i.e. just writes some info to a DB or log file), and then passes the request off to the built-in method ?

def DownloadStudy(output, uri, **request):

  1. do some stuff like logging to a file or DB
  2. pass the request off to the native method vs. use output.AnswerBuffer() to generate what the the native method would return.

orthanc.RegisterRestCallback(‘/studies/(.*)/archive’, DownloadStudy)

The reason I might want to do that is because the request in some cases has some data in the headers or elsewhere that identifies the user making the request and I’d like to log that in some cases.

Thanks.

/sds

Hi Stephen,

RestApiGet calls the bare OrthancApi.
RestApiGetAfterPlugins calls the OrthancApi including the routes defined/replaced by plugins.

In your case, you’ll want to use RestApiGet to avoid an infinite recursion.

HTH,

Alain

def OnDownloadStudy(output, uri, **request):
orthanc.LogInfo(f"download study {uri}")

archive = orthanc.RestApiGetAfterPlugins(uri) → this would lead to an infinite recursion since it would call the python plugin again and again

archive = orthanc.RestApiGet(uri)
output.AnswerBuffer(archive, ‘application/zip’)

orthanc.RegisterRestCallback(‘/studies/(.*)/archive’, OnDownloadStudy)