Restful Service HTTP Methods

The RESTful Service is provided by the REST API that supports 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 or update / updateMultiple actions.
  3. DELETE - can be used to perform take / takeMultiple actions either by ID or by a space query.

Introduce Type

Description Introduce the specific type to space.
Request URL PUT http://localhost:8080/{Type}/_introduce_type

Request Schema:

{
  "idProperty": { //required
    "propertyName": "id",
    "autoGenerated": true, // optional
    "indexType": "EQUAL" // optional, use with autoGenerate. SEE com.gigaspaces.metadata.index.SpaceIndexType
  },
  "routingProperty": {
    "propertyName": "id",
    "indexType": "EQUAL" // optional. SEE com.gigaspaces.metadata.index.SpaceIndexType
  },
  "fixedProperties": [
    {
      "propertyName": "id",
      "propertyType": "int32" // predefined types or full Java class path*
    },
    {
      "propertyName": "prop1",
      "propertyType": "string", // predefined types or full Java class path*
      "documentSupport": "DEFAULT" // optional. SEE com.gigaspaces.metadata.SpaceDocumentSupport
    },
    {
      "propertyName": "prop2",
      "propertyType": "java.util.Map", // predefined types or full Java class path*
      "documentSupport": "DEFAULT", // optional. SEE com.gigaspaces.metadata.SpaceDocumentSupport
      "storageType": "DEFAULT" // optional, use with documentSupport. SEE com.gigaspaces.metadata.StorageType
    },
    {
      "propertyName": "indexedProp",
      "propertyType": "string", // predefined types or full Java class path*
      "indexType": "EQUAL", // optional. SEE com.gigaspaces.metadata.index.SpaceIndexType
      "uniqueIndex": true // optional, must be used with indexType field only. Default to false.
    }
  ],
  "compoundIndex": {
    "paths": [
      "prop1",
      "prop2"
    ],
    "unique": true // optional
  },
  "fifoSupport": "DEFAULT", // SEE com.gigaspaces.annotation.pojo.FifoSupport
  "blobStoreEnabled": true,
  "storageType": "DEFAULT", // SEE com.gigaspaces.metadata.StorageType
  "supportsOptimisticLocking": true,
  "supportsDynamicProperties": false // optional, default to true
}

Response Schema:

{
   "status":"success"
}

Predefined types and their conversion:

Type name Java class
int32 java.lang.Integer
int64 java.lang.Long
double java.lang.Double
number java.lang.Double
float java.lang.Float
boolean java.lang.Boolean
string java.lang.String
datetime java.util.Date
array java.util.List
set java.util.Set
sortedset java.util.SortedSet
object com.gigaspaces.document.SpaceDocument

Examples:

curl -XPUT -H "Content-Type: application/json" -d '{"idProperty":{"propertyName":"id","autoGenerated":false},"routingProperty":{"propertyName":"id"},"fixedProperties":[{"propertyName":"id","propertyType":"int64"},{"propertyName":"name","propertyType":"string"},{"propertyName":"age","propertyType":"java.lang.Integer"}]}' http://localhost:8080/MyObject/_introduce_type

Write

Description Write single entry to the space.
Request URL POST http://localhost:8080/{Type}/
Request Headers Content-Type: application/json
Request Body JSON object representation of a SpaceDocument object.

Response Schema:

{
   "status":"success"
}

Examples:

curl -XPOST -H "Content-Type: application/json" -d '{"id":1, "name":"myName", "age":10}' http://localhost:8080/MyObject

Write Multiple

Description Write multiple entries to the space.
Request URL POST http://localhost:8080/{Type}/
Request Headers Content-Type: application/json
Request Body JSON array representation of a SpaceDocument objects.

Response Schema:

{
   "status":"success"
}

Examples:

curl -XPOST -H "Content-Type: application/json" -d '[{"id":2, "name":"John", "age":16},
{"id":3, "name":"Michael", "age":18}]' http://localhost:8080/MyObject

Count

Description Returns the number of entries in space of the specified type
Request URL GET http://localhost:8080/{Type}/count

Response Schema:

{
   "status":"success",
   "data":0
}

Examples:

curl -XGET http://localhost:8080/{Type}/count

Read Multiple

Description Read multiple entries from space that matches the query.
Request URL GET http://localhost:8080/{Type}/
Request Query Parameters query - a SQLQuery that is a SQL-like syntax
max - the maximum amount of entries to read

Response Schema:

{
   "status":"success",
   "data":[
      {
         "id":1,
         "name":"First"
      },
      {
         "id":2,
         "name":"Second"
      }
   ]
}

Examples:

curl -XGET http://localhost:8080/MyObject/?query=age='10'
curl -XGET http://localhost:8080/MyObject/?query=id=%271%27%20or%20id=%272%27%20or%20id=%273%27

*The url is encoded, the query is: id="1' or id="2' or id="3'

Read By Id

Description Read entry from space with the provided id
Request URL GET http://localhost:8080/{Type}/{id}

Response Schema:

{
   "status":"success",
   "data":{
      "id":1,
      "name":"First"
   }
}

Examples:

curl -XGET http://localhost:8080/MyObject/1
curl -XGET http://localhost:8080/MyObject/2
curl -XGET http://localhost:8080/MyObject/3

Update Multiple

Description Update entries in space
Request URL POST http://localhost:8080/{Type}

Response Schema:

{
   "status":"success"
}

Examples:

curl -XPOST -H "Content-Type: application/json" -d '[{"id":1,"name":"myName","age":11},{"id":2,"name":"John","age":17},{"id":3,"name":"Michael","age":19}]' http://localhost:8080/MyObject

See that data2 field is updated:

curl http://localhost:8080/MyObject/?query=age=11

Take Multiple

Description Gets and deletes entries from space that matches the query.
Request URL DELETE http://localhost:8080/{Type}/
Request Query Parameters query - a SQLQuery that is a SQL-like syntax

Response Schema:

{
   "status":"success",
   "data":[
        {
           "id":1,
           "name":"First"
        },
        {
           "id":2,
           "name":"Second"
        }
     ]
}

Examples:

curl -XDELETE http://localhost:8080/MyObject/?query=id=%271%27%20or%20id=%272%27

*The url is encoded, the query is: id=1 or id=2

See that only Item3 remains:

curl -XGET http://localhost:8080/MyObject/?query=id=%271%27%20or%20id=%272%27%20or%20id=%273%27

Take By Id

Description Gets and deletes the entry from space with the provided id
Request URL DELETE http://localhost:8080/{Type}/{id}

Response Schema:

{
   "status":"success",
   "data":{
         "id":1,
         "name":"First"
      }
}

Examples:

curl -XDELETE http://localhost:8080/MyObject/3

See that Item3 does not exists:

curl -XGET http://localhost:8080/MyObject/?query=id=%271%27%20or%20id=%272%27%20or%20id=%273%27