第11章 REST インターフェース

Red Hat JBoss Data Grid は、REST インターフェースを提供します。REST API の主な利点は、クライアントとサーバー間で疎結合が可能になることです。クライアントライブラリーおよびバインディングの特定のバージョンに対する依存性がなくなります。REST API によりオーバーヘッドが発生し、REST クライアントまたはカスタムコードが REST コールを認識し、作成する必要があります。
JBoss Data Grid の REST API と対話するには、HTTP クライアントライブラリーのみが必要です。Java の場合は、Apache HTTP Commons Client が推奨されます。または、java.net API を使用できます。

重要

以下の例では、REST セキュリティーが REST コネクターで無効にされていることを前提とします。REST セキュリティーを無効にするには、コネクターから security-domain および auth-method パラメーターを削除します。

11.1. Ruby クライアントコード

以下のコードは ruby を使用して Red Hat JBoss Data Grid REST API と対話する例です。提供されたコードは特別なライブラリーを必要とせず、標準的な net/HTTP ライブラリーで十分です。

例11.1 Ruby での REST API の使用

require 'net/http'

http = Net::HTTP.new('localhost', 8080)

#An example of how to create a new entry

http.post('/rest/MyData/MyKey', 'DATA_HERE', {"Content-Type" => "text/plain"})

#An example of using a GET operation to retrieve the key

puts http.get('/rest/MyData/MyKey').body

#An Example of using a PUT operation to overwrite the key

http.put('/rest/MyData/MyKey', 'MORE DATA', {"Content-Type" => "text/plain"})

#An example of Removing the remote copy of the key

http.delete('/rest/MyData/MyKey')

#An example of creating binary data

http.put('/rest/MyImages/Image.png', File.read('/Users/michaelneale/logo.png'), {"Content-Type" => "image/png"})