![]() |
Page History
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
package mayo.edu.cts2.client.rest.scala import java.net.{HttpURLConnection, URL} import io.Source /** * Created with IntelliJ IDEA. * Author: Scott Bauer bauer.scott@mayo.edu * Date: 10/2/12 * Time: 3:17 PM */ object CTS2RestClient extends App{ val connection = new URL("http://informatics.mayo.edu/cts2/rest/valuesets").openConnection().asInstanceOf[HttpURLConnection] val inputStream = connection.getInputStream val src = Source.fromInputStream(inputStream) src.getLines().foreach(println) } |
Python
Install Python on your system. Create a text file with the .py extension and run with the "python myrestclient.py" command
Code Block |
---|
__author__ = 'sbauer'
import urllib2
try:
file = urllib2.urlopen('http://bmidev4:5555/cts2/resolvedvaluesets')
except urllib2.URLError, e:
if e.code == 404:
print("check url")
# continue to handle other errors here
else:
print(file.read()) |
Python must be installed on your system. Download the third party library python-rest-client. Add python-rest-client to the PYTHONPATH environment variable to your system. Create a python script file and run as above.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
__author__ = 'sbauer' from restful_lib import Connection conn = Connection("http://informatics.mayo.edu/cts2/rest") reply = conn.request_get("/valuesets") if reply['headers']['status'] == '200': print reply['body'] conn = Connection("http://informatics.mayo.edu/cts2/rest") reply = conn.request_get("/valuesets?format=json",headers={'Accept':'application/json;q=1.0'}) if reply['headers']['status'] == '200': print reply['body'] print eval(reply['body']) conn = Connection("http://informatics.mayo.edu/cts2/rest") print conn.request_get("/valuesets?matchvalue='Sequence'")['body'] |
...