11.3. Python クライアントコード

以下のコードは Python を使用して Red Hat JBoss Data Grid REST API と対話する例です。提供されたコードは、標準的な HTTP ライブラリーのみを必要とします。

例11.2 Python での REST API の使用

import httplib  

#How to insert data

conn = httplib.HTTPConnection("localhost:8080")
data = "SOME DATA HERE \!" #could be string, or a file...
conn.request("POST", "/rest/default/0", data, {"Content-Type": "text/plain"})
response = conn.getresponse()
print response.status

#How to retrieve data

import httplib
conn = httplib.HTTPConnection("localhost:8080")
conn.request("GET", "/rest/default/0")
response = conn.getresponse()
print response.status
print response.read()