A simple way to invoke the HPE Ezmeral Data Fabric Database JSON REST API is to use cURL
commands. This section contains a sequence cURL commands that demonstrate
the basic functionality of the API.
To learn about the complete API, see the reference material at Understanding the HPE Ezmeral Data Fabric Database JSON REST API.
10.10.100.42. The examples use HTTPS with the default
HTTPS port of 8243. For information about installing the Data
Access Gateway, see Installing the Data Access Gateway Service.%2F) to differentiate them from the slashes in the command
API.The commands in this section use basic authentication. To use this form of
authentication, you must pass the username and password in all commands, using the
-u option.
/apps/employees:
curl -X PUT \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees' \
-u root:mapr
curl -X POST \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees' \
-u root:mapr \
-H 'Content-Type: application/json' \
-d '[{"_id":"user001","first_name":"John","last_name":"Doe"},
{"_id":"user002","first_name":"Jane","last_name":"Doe"},
{"_id":"user003","first_name":"Simon","last_name":"Davis"}]'
curl -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees%2F' \
-u root:mapr
{
"DocumentStream": [
{
"_id": "user001",
"first_name": "John",
"last_name": "Doe"
},
{
"_id": "user002",
"first_name": "Jane",
"last_name": "Doe"
},
{
"_id": "user003",
"first_name": "Simon",
"last_name": "Davis"
}
]
}GET request to 2 documents starting at offset
1:
curl -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees%2F?offset=1&limit=2' \
-u root:mapr
{
"DocumentStream": [
{
"_id": "user002",
"first_name": "Jane",
"last_name": "Doe"
},
{
"_id": "user003",
"first_name": "Simon",
"last_name": "Davis"
}
]
}curl -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees?fields=first_name' \
-u root:mapr
{
"DocumentStream": [
{
"first_name": "John"
},
{
"first_name": "Jane"
},
{
"first_name": "Simon"
}
]
}'Doe':
curl -g -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees?condition={"$eq":{"last_name":"Doe"}}' \
-u root:mapr
'-g' in the cURL
command due to the nested braces in the condition.{
"DocumentStream": [
{
"_id": "user001",
"first_name": "John",
"last_name": "Doe"
},
{
"_id": "user002",
"first_name": "Jane",
"last_name": "Doe"
}
]
}'Doe':
curl -g -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees?condition={"$eq":{"last_name":"Doe"}}&fields=_id,first_name' \
-u root:mapr
'-g' in the cURL
command due to the nested braces in the condition.{
"DocumentStream": [
{
"_id": "user001",
"first_name": "John"
},
{
"_id": "user002",
"first_name": "Jane"
}
]
}curl -g -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees?condition={"$eq":{"last_name":"Doe"}}&fields=_id,first_name&getPlan=true' \
-u root:mapr
{
"DocumentStream": [
{
"_id": "user001",
"first_name": "John"
},
{
"_id": "user002",
"first_name": "Jane"
}
],
"QueryPlan": [
[
{
"streamName": "DBDocumentStream",
"parameters": {
"queryConditionPath": true,
"projectionPath": [
"_id",
"first_name"
],
"primaryTable": "/apps/employees"
}
}
]
]
}id in the command:
curl -X POST \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees/document/user001' \
-H 'Content-Type: application/json' \
-u root:mapr \
-d '{"$set":{"first_name":"Jay"}}'
id in the
command:
curl -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees/document/user001' \
-u root:mapr
{
"_id": "user001",
"first_name": "Jay",
"last_name": "Doe"
}curl -X PUT \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees/document/user001' \
-H 'Content-Type: application/json' \
-u root:mapr \
-d '{"_id":"user001","first_name":"Jonathan"}'
id in the
request:
curl -X GET \
'https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees/document/user001' \
-u root:mapr
The document contains only a first name:
{
"_id": "user001",
"first_name": "Jonathan"
}
To use token-based authentication, you first create a token, authenticating with a username and password. You then pass the generated token in all subsequent commands.
curl -X POST \
'https://10.10.100.42:8243/auth/v2/token' \
-u root:mapr{
"token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJyb290IiwiYXVkIjoid2ViIiwiZXhwIjoxNTIwMjY5MTQwLCJpYXQiOjE1MjAyNjczNDB9.NT8L2deiA6v55bfbU_opiG1XXGPP0IwfSex3jW5A1ZsoI1ar09it7-XwNtRqfL_I29IHLyfmuHcT5eSIpwq6ng"
}cURL command, as shown in the following
GET:curl -X GET \
https://10.10.100.42:8243/api/v2/table/%2Fapps%2Femployees \
-H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJyb290IiwiYXVkIjoid2ViIiwiZXhwIjoxNTIwMjY5MTQwLCJpYXQiOjE1MjAyNjczNDB9.NT8L2deiA6v55bfbU_opiG1XXGPP0IwfSex3jW5A1ZsoI1ar09it7-XwNtRqfL_I29IHLyfmuHcT5eSIpwq6ng'