diff Resources/Samples/Lua/CallWebService.lua @ 1055:6f923d52a46c

call Web services from Lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Jul 2014 11:37:02 +0200
parents
children 65b1ce7cb84f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Samples/Lua/CallWebService.lua	Thu Jul 24 11:37:02 2014 +0200
@@ -0,0 +1,24 @@
+-- This sample shows how to call a remote Web service whenever an
+-- instance is received by Orthanc. For this sample to work, you have
+-- to start the "CallWebService.js" script next to this file using
+-- NodeJs.
+
+-- Download and install the JSON module for Lua by Jeffrey Friedl
+-- http://regex.info/blog/lua/json
+JSON = (loadstring(HttpGet('http://regex.info/code/JSON.lua'))) ()
+
+SetHttpCredentials('alice', 'alicePassword')
+
+function OnStoredInstance(instanceId, tags, metadata)
+   -- Build the POST body
+   local info = {}
+   info['InstanceID'] = instanceId
+   info['PatientName'] = tags['PatientName']
+   info['PatientID'] = tags['PatientID']
+
+   -- Send the POST request
+   local answer = HttpPost('http://localhost:8000/', JSON:encode(info))
+
+   -- The answer equals "ERROR" in case of an error
+   print('Web service called, answer received: ' .. answer)
+end