docs.intersystems.com
Home  /  Application Development: Additional Options  /  Using Document Database (DocDB)  /  REST Client Methods


Using Document Database (DocDB)
REST Client Methods
[Back] 
InterSystems: The power behind what matters   
Search:  


The InterSystems IRIS Data Platform™ DocDB REST Client API supplies methods that enable you to work with DocDB from REST. The REST API differs from other DocDB APIs because REST acts on resources while the other APIs act on objects. This resource orientation is fundamental to the nature of REST.
The curl examples in this chapter specify port number 57774. This is only an example. You should use the port number appropriate for your InterSystems IRIS instance.
In curl the GET command is the default; therefore, a curl command that omits -X GET defaults to -X GET.
For further details on the REST API refer to the %Api.DocDB.v1 in the InterSystems Class Reference. For further details on REST, refer to Creating REST Services.
Managing Databases
Managing Properties
The following is a JSON property definition:
{"content":{"Name":"mydocdb","Class":"DB.MyDocDb","properties":[Array[5]
   0: {"Name":%%OTD,"Type":"%Library.CacheString"},
   1: {"Name":%Concurrency,"Type":"%Library.CacheString"},
   2: {"Name":%Doc,"Type":"%Library.DynamicAbstractObject"},
   3: {"Name":%DocumentId,"Type":"%Library.Integer"},
   4: {"Name":%LastModified,"Type":"%Library.UTC"}
   ]}}
Inserting and Updating Documents
Deleting Documents
Retrieving a Document
The following curl script example supplies full user credentials and header information. It returns all of the documents in the Continents document database in the MySamples namespace:
curl --user _SYSTEM:SYS -w "\n\n%{http_code}\n" -X POST 
-H "Accept: application/json" -H "Content-Type: application/json" 
http://localhost:57774/api/docdb/v1/mysamples/find/continents
It returns JSON data from the Document database such as the following:
{"content":{"sqlcode":100,"message":null,"content":[
  {"%Doc":"{\"code\":\"NA\",\"name\":\"North America\"}","%DocumentId":"1","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"SA\",\"name\":\"South America\"}","%DocumentId":"2","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"AF\",\"name\":\"Africa\"}","%DocumentId":"3","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"AS\",\"name\":\"Asia\"}","%DocumentId":"4","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"EU\",\"name\":\"Europe\"}","%DocumentId":"5","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"OC\",\"name\":\"Oceana\"}","%DocumentId":"6","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"AN\",\"name\":\"Antarctica\"}","%DocumentId":"7","%LastModified":"2018-02-15 21:33:03.64"}]}}
Restriction: The following curl script example restricts the documents returned from the Continents document database by specifying a restriction object. This restriction limits the documents returned to those whose name begins with the letter A:
curl --user _SYSTEM:SYS -w "\n\n%{http_code}\n" -X POST 
-H "Accept: application/json" -H "Content-Type: application/json" 
http://localhost:57774/api/docdb/v1/mysamples/find/continents -d
'{"restriction":["Name","A","%STARTSWITH"]}'
It returns the following JSON documents from the Document database:
{"content":{"sqlcode":100,"message":null,"content":[
  {"%Doc":"{\"code\":\"AF\",\"name\":\"Africa\"}","%DocumentId":"3","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"AS\",\"name\":\"Asia\"}","%DocumentId":"4","%LastModified":"2018-02-15 21:33:03.64"},
  {"%Doc":"{\"code\":\"AN\",\"name\":\"Antarctica\"}","%DocumentId":"7","%LastModified":"2018-02-15 21:33:03.64"}]}}
Projection: The following curl script example projects which JSON properties to return from each document in the Continents document database. It uses the same restriction as the previous example:
curl --user _SYSTEM:SYS -w "\n\n%{http_code}\n" -X POST 
-H "Accept: application/json" -H "Content-Type: application/json" 
http://localhost:57774/api/docdb/v1/mysamples/find/continents -d
'{"restriction":["Name","A","%STARTSWITH"],"projection":["%DocumentId","name"]}'
It returns JSON data from the Document database such as the following:
{"content":{"sqlcode":100,"message":null,"content":[
  {"%Doc":"{"%DocumentId":"3","name":"Africa"}},
  {"%Doc":"{"%DocumentId":"4","name":"Asia"}},
  {"%Doc":"{"%DocumentId":"7","name":"Antarctica"}}]}}