This page describes an older version of the product. The latest stable version is 14.0.

REST API


The REST API exposing HTTP based interface Space. It is leveraging the GigaSpace API. It support the following methods:

  1. GET - can be used to perform an introduceType, readByID or a readMultiple action by a space query.
  2. POST - can be used to perform a write / writeMultiple action.
  3. PUT - can be used to perform a single or multiple write or update actions.
  4. DELETE - can be used to perform take / takeMultiple actions either by ID or by a space query.

POST is mapped to a WriteOnly action. An exception will be thrown when trying to write an object which already exists in space.

Examples

Note that space and locators parameters can be passed to each request. If not, defaultSpaceName that is defined in config.properties will be used as space and localhost as locators. In the following examples we are passing space=myDataGrid. locators=localhost will be used as it is not passed.

  • introduceType
http://localhost:8080/RESTData/rest/data/Item/_introduce_type?space=myDataGrid&spaceid=id
  • writeMultiple
curl -XPOST -H "Content-Type: application/json" -d '[{"id":"1", "data":"testdata", "data2":"common", "nestedData" : {"nestedKey1":"nestedValue1"}},
{"id":"2", "data":"testdata2", "data2":"common", "nestedData" : {"nestedKey2":"nestedValue2"}},
{"id":"3", "data":"testdata3", "data2":"common", "nestedData" : {"nestedKey3":"nestedValue3"}}]'
http://localhost:8080/RESTData/rest/data/Item?space=myDataGrid
  • count
http://localhost:8080/RESTData/rest/data/Item/count?space=myDataGrid
  • readMultiple
http://localhost:8080/RESTData/rest/data/Item/_criteria?q=data2='common'
http://localhost:8080/RESTData/rest/data/Item/_criteria?q=id=%271%27%20or%20id=%272%27%20or%20id=%273%27&space=myDataGrid

The url is encoded, the query is “id=‘1’ or id=‘2’ or id=‘3’”.

  • readById
http://localhost:8080/RESTData/rest/data/Item/1?space=myDataGrid
http://localhost:8080/RESTData/rest/data/Item/2?space=myDataGrid
http://localhost:8080/RESTData/rest/data/Item/3?space=myDataGrid
  • updateMultiple
curl -XPUT -H "Content-Type: application/json" -d '[{"id":"1", "data":"testdata", "data2":"commonUpdated", "nestedData" : {"nestedKey1":"nestedValue1"}},
{"id":"2", "data":"testdata2", "data2":"commonUpdated", "nestedData" : {"nestedKey2":"nestedValue2"}},
{"id":"3", "data":"testdata3", "data2":"commonUpdated", "nestedData" : {"nestedKey3":"nestedValue3"}}]' 
http://localhost:8080/RESTData/rest/data/Item?space=myDataGrid

See that data2 field is updated:

http://localhost:8080/RESTData/rest/data/Item/_criteria?q=data2='commonUpdated'&space=myDataGrid

Single nested update:

curl -XPUT -H "Content-Type: application/json" -d '{"id":"1", "data":"testdata", "data2":"commonUpdated", "nestedData" : {"nestedKey1":"nestedValue1Updated"}}' http://localhost:8080/RESTData/rest/data/Item?space=myDataGrid

See that Item1 nested field is updated:

http://localhost:8080/RESTData/rest/data/Item/1?space=myDataGrid
  • takeMultiple (url is encoded, the query is “id=1 or id=2”)
curl -XDELETE http://localhost:8080/RESTData/rest/data/Item/_criteria?q=id=%271%27%20or%20id=%272%27&space=myDataGrid

See that only Item3 remains:

http://localhost:8080/RESTData/rest/data/Item/_criteria?q=id=%271%27%20or%20id=%272%27%20or%20id=%273%27&space=myDataGrid
  • takeById
curl -XDELETE "http://localhost:8080/RESTData/rest/data/Item/3?space=myDataGrid"

See that Item3 does not exists:

http://localhost:8080/RESTData/rest/data/Item/_criteria?q=id=%271%27%20or%20id=%272%27%20or%20id=%273%27&space=myDataGrid

Setup Instructions

1.Download the project from the github repository

2.Edit “/RESTData/src/main/webapp/WEB-INF/config.properties” to include your space name, for example: defaultSpaceName=myDataGrid

Note: This is a default space name. You can override it by passing space parameter to the request.

3.Package the project using maven: “mvn package”. This will run the unit tests and package the project to a war file located at /target/RESTData.war

4.Deploy the war file.