comparison 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
comparison
equal deleted inserted replaced
1054:1701dcb6f554 1055:6f923d52a46c
1 -- This sample shows how to call a remote Web service whenever an
2 -- instance is received by Orthanc. For this sample to work, you have
3 -- to start the "CallWebService.js" script next to this file using
4 -- NodeJs.
5
6 -- Download and install the JSON module for Lua by Jeffrey Friedl
7 -- http://regex.info/blog/lua/json
8 JSON = (loadstring(HttpGet('http://regex.info/code/JSON.lua'))) ()
9
10 SetHttpCredentials('alice', 'alicePassword')
11
12 function OnStoredInstance(instanceId, tags, metadata)
13 -- Build the POST body
14 local info = {}
15 info['InstanceID'] = instanceId
16 info['PatientName'] = tags['PatientName']
17 info['PatientID'] = tags['PatientID']
18
19 -- Send the POST request
20 local answer = HttpPost('http://localhost:8000/', JSON:encode(info))
21
22 -- The answer equals "ERROR" in case of an error
23 print('Web service called, answer received: ' .. answer)
24 end