-
Notifications
You must be signed in to change notification settings - Fork 0
REST API
This API provides the functionality related to the user management such as user registrations, login and logout.
This API can be used to create new user in the application. When user created, by default its status is active.
Note:
Email and password fields is required in registration new user. Additional property can also included in the request
body.
Return: Created user account information.
Method: POST
URL: /v1/< application-id >/users/register
Headers:
Authorization: {user token after login in Dena platform}
Content-Type : application/json
Body: {JSON}
Example:
Request Body:
{
"email": "user1@dena-platform.com",
"password": "123456",
"name":"javad",
"family":"alimohammadi"
... other fields
}
Response Body:
{
"timestamp": 1520504910721,
"create_user_count": 1,
"objects": [
{
"object_id": "5b2bc6848db73a10ac999947",
"object_uri": "/DENA_USER/5b2bc6848db73a10ac999947",
"update_time": null,
"create_time": 1529595524645,
"password": "$2a$10$b802T370w6I80joRAHgYP.cdO83PIzRt.eBYN1/hBok17/GsS2lxC",
"name": "javad",
"family": "alimohammadi",
"email": "user3@dena-platform.com"
... other fields
}
]
}
With this API user can login in Dena Platform. After user successfully login then in subsequent request access token should be included in the request.
Return: Logged in user information except password.
Method: POST
URL: /v1/< application-id >/users/login
Headers:
Content-Type:application/json
Body: {JSON}
Example:
Request Body:
{
"email": "user1@dena-platform.com",
"password": "123456"
}
Response Body:
{
"timestamp": 1531160269366,
"found_object_count(s)": 1,
"objects": [
{
"object_id": "5b3f2959daf29de3ccf75ac0",
"object_uri": "/DENA_USER/5b3f2959daf29de3ccf75ac0",
"update_time": 1530901422412,
"create_time": 1530866009459,
"is_active": null,
"name": "javad",
"family": "alimohammadi",
"email": "user1@dena-platform.com",
"token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyMUBkZW5hLXBsYXRmb3JtLmNvbSIsImV4cCI6MTUzMTE3NDY2MCwicm9sZSI6ImZpeGVkX3JvbGUiLCJhcHBfaWQiOiJkZW5hUUEiLCJ1c2VyTmFtZSI6InVzZXIxQGRlbmEtcGxhdGZvcm0uY29tIiwiY3JlYXRpb25fZGF0ZSI6eyJlcG9jaFNlY29uZCI6MTUzMTE2MDI2MCwibmFubyI6NzU0MDAwMDAwfX0.zFKdWGTjgqK2WgabThHf9qf7EbGajncFDCMRkesnZq-PAfJ32jp_jIzGQpN7yhJ7CkAmty9DtnceshK6ZM_Wbw"
}
]
}
With this API user can logout in Dena Platform.
Return: Success logout message.
Method: POST
URL: /v1/< application-id >/users/logout
Headers: Authorization: {user token after login in Dena platform} Content-Type:application/json
Body: {JSON}
Example:
Request Body:
{
"email": "user1@dena-platform.com"
}
Response Body:
{
"timestamp": 1531162294570,
"objects": [
{
"Message": " User logout successfully"
}
]
}
Schema is the structure of tables in Dena platform. With schema, developers can get table structure, add/remove columns and define constrains on columns (not implemented yet).
Return: Number of created table.
Method: POST
URL: /v1/< application-id >/schema/
Headers:
Authorization: {user token after login in Dena platform}
Content-Type: application/json
Body: {None}
Example:
Request Body:
Empty
Response Body:
{
"status":200,
"timestamp": 1520504910721,
"create_table_count(s)": 1
}
Return: All created schema in appliaction.
Method: GET
URL: /v1/< application-id >/schema
Headers:
Authorization: {user token after login in dena-platform}
Body: {None}
Example:
Request Body: {None}
Response Body:
{
"status":200,
"timestamp": 1520504910721,
"count": 2,
"objects": [
{
"name": "table1",
"record_count":123
},
{
"name": "table2",
"record_count":123
}
]
}
Return: Number of deleted table.
Method: DELETE
URL: /v1/< application-id >/schema/{table-name}
Headers:
Authorization: {user token after login in dena-platform}
Body: {None}
Example:
Request Body: {None}
Response Body:
{
"timestamp": 1520504910721,
"delete_table_count(s)": 1
}
Create new object in Dena data store.
Create Single Object
Return: Created object(s) count.
Method: POST
URL: /v1/< application-id >/< table-name >/?loadRelation=false
Headers:
Content-Type:application/json
Authorization: {user token after login in Dena platform}
Body: {JSON}
Optional Parameter
- loadRelation: Whether load relation after creating object.
Example:
Request Body:
{
"name": "javad",
"job": "developer"
}
Response Body:
{
"timestamp": 1520504910721,
"count": 1,
"objects": [
{
"object_id": "5aa1104e99d0b323487d38a1",
"object_uri": "/posts/5aa1104e99d0b323487d38a1",
"update_time": null,
"creation_time": 1520504910672,
}
]
}
Create Bulk Objects
This API is same is above with the exception that the request can contain
multiple request.
Return: Created object(s) count.
Method: POST URL: /v1/< application-id >/?loadRelation=false
Headers:
Content-Type:application/json
Authorization: {user token after login in Dena platform}
Body: {JSON}
Optional Parameter
- loadRelation: Whether load relation after creating object.
Example:
Request Body:
[
{
"field1": "javad",
"field2": "developer",
"related_objects": [
{
"relation_name": "comments_rel",
"target_name": "comments",
"ids": [
"5aa52335d41a3b18c8bdbe28"
]
}
]
},
{
"field1": "ali",
"field2": "developer",
"related_objects": [
{
"relation_name": "comments_rel",
"target_name": "comments",
"ids": [
"5aa52335d41a3b18c8bdbe28"
]
}
]
}
]
Response Body:
{
"timestamp": 1521833800182,
"create_object_count(s)": 2,
"objects": [
{
"object_id": "5ab557484611681f7c07a6dd",
"object_uri": "/post/5ab557484611681f7c07a6dd",
"update_time": null,
"create_time": 1521833800007,
"field1": "javad",
"field2": "developer"
},
{
"object_id": "5ab557484611681f7c07a6de",
"object_uri": "/post/5ab557484611681f7c07a6de",
"update_time": null,
"create_time": 1521833800099,
"field3": "javad",
"field4": "developer"
}
]
}
Related object should exist before calling this API.
There are two approach to create relation between objects.
- Create relation when requesting create new object.
- Use separate API for creating relation between objects.
Create relation when requesting create new object
Relation specifies in related_objects field.
Begin Implementation Detail
related_objects contain three field
- relation_name: name of relation in Dena platform. we store it so when we retrieve a Dena object we can recognize field.
- target_type: name of destination relation type. To recognize destination type for example when we want show destination type in panel.
- id: ids of destination type.
In response to client Dena do not return relation objects because of performance consideration.
End Implementation Detail
Method: POST
URL: /v1/< application-id >/
Headers:
Content-Type:application/json
Authorization: {user token after login in Dena platform}
Body: {JSON}
Example:
Request Body:
{
"field1": "javad",
"field2": "developer",
"related_objects": [
{
"relation_name":"comments_rel",
"target_name":"comments",
"id": ["5a206dc2cc2a9b26e483d664", "5a206dc2cc2a9b26e483d634"]
}
]
}
Response Body:
{
"timestamp" : timestamp in milliseconds,
"count" : number of created object(s),
"objects": [
{
"URI":"/<type-name>/<object-id>",
"object_id": "5a206dc2cc2a9b26e483d664",
"field1": "javad",
"field2": "developer"
}
]
}
Use separate API for creating relation between objects (TO-DO)
Update (Merge) One Object
- If there is a new field or relation then create it.
- If field is exist then update it.
- If relation with same name exist in data store and related object not stored before then add it, otherwise ignore it.
- If object id is not found then return bad request error.
- If data in relation is invalid for example object id not exist or target type not found then return bad request error.
Return: Updated object(s) count.
Method: PATCH
URL: /v1/< application-id >/?loadRelation=false
Headers:
Content-Type:application/json
Authorization: {user token after login in Dena platform}
Body: {JSON}
Optional Parameter
- loadRelation: Whether load relation after updating object.
Example:
Request Body:
{
"object_id": "5aa69e99d41a3b2480ec35b0",
"field3": "javad",
"new_field": "new_field_v1",
"related_objects": [
{
"relation_name": "comments_rel",
"target_name": "comments",
"ids": [
"5aa9348ed41a3b25b8b49b79"
]
}
]
}
Response Body:
{
"timestamp": 1521095130350,
"status":200,
"update_object_count": 1,
"objects": [
{
"object_id": "5aaa0ae6ecb1ef188094eed0",
"object_uri": "/post/5aaa0ae6ecb1ef188094eed0",
"update_time": 1521095130344,
"create_time": 1521093350371,
"field1": "javad",
"new_field": "new_field_v1",
"field3": "javad",
"field2": "developer"
}
]
}
Update (Replace) One Object
Completely replace object in Dena data-store. remove all previous data and add new requested data .
Return: Updated object(s) count.
Method: PUT
URL: /v1/< application-id >/?loadRelation=false
Headers:
Content-Type:application/json
Authorization: {user token after login in Dena platform}
Body: {JSON}
Optional Parameter
- loadRelation: Whether load relation.
Example:
Request Body:
{
"object_id": "5aa69e99d41a3b2480ec35b0",
"field3": "javad",
"new_field": "new_field_v1",
"related_objects": [
{
"relation_name": "comments_rel",
"target_name": "comments",
"ids": [
"5aa9348ed41a3b25b8b49b79"
]
}
]
}
Response Body:
{
"timestamp": 1521095130350,
"status":200,
"update_object_count": 1,
"objects": [
{
"object_id": "5aaa0ae6ecb1ef188094eed0",
"object_uri": "/post/5aaa0ae6ecb1ef188094eed0",
"update_time": 1521095130344,
"create_time": 1521093350371,
"new_field": "new_field_v1",
"field3": "javad"
}
]
}
Bulk (Merge) Update Objects
if there is a new field or new relation(new type) add to existing fields or relations. if field is exist then update field.
If relation with same type exist then replace with new specified relation.
Return: updated object(s) with only updated fields and relation.
Method: PATCH URL: /v1/< application-id >/
Headers:
Content-Type:application/json
Authorization: {user token after login in Dena platform}
Body: {JSON}
Example:
Request Body:
[
{
"field1": "javad",
"field2": "developer",
"related_objects": [
{
"relation_name": "comment_relation",
"relation_type": "ONE-TO-ONE",
"target_name": "comment",
"ids": [
"5aaa095eecb1ef188094eece"
]
}
]
},
{
"field3": "javad",
"field4": "developer",
"related_objects": [
{
"relation_name": "comment_relation",
"relation_type": "ONE-TO-ONE",
"target_name": "comment",
"ids": [
"5aaa0982ecb1ef188094eecf"
]
}
]
}
]
Response Body:
{
"timestamp": 1521095304269,
"update_object_count": 2,
"objects": [
{
"object_id": "5aaa0ae6ecb1ef188094eed0",
"object_uri": "/post/5aaa0ae6ecb1ef188094eed0",
"update_time": 1521095304258,
"create_time": 1521093350371,
"field1": "javad",
"new_field": "new_field_v1",
"field3": "javad",
"field2": "developer"
},
{
"object_id": "5aaa0c05ecb1ef188094eed3",
"object_uri": "/post/5aaa0c05ecb1ef188094eed3",
"update_time": 1521095304263,
"create_time": 1521093637106,
"field1": "javad",
"new_field": "new_field_v1",
"field3": "javad",
"field2": "developer"
}
]
}
Delete One Object
This API remove object completely from Dena storage. If the object is successfully deleted then API returns the timestamp of deletion time in milliseconds and number of deleted object count.
Return: Number of deleted object count.
Method: DELETE
URL: /v1/< application-id >//
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Body: {None}
Example:
Request Body: {None}
Response Body:
{
"timestamp": 1521104923089,
"status":200,
"delete_object_count(s)": 1
}
Delete Bulk Objects
Return: Number of deleted object counts.
Method: DELETE
URL: /v1/< application-id >//<object-id-1,object-id-2>
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Example:
Request Body: {None}
Response Body:
{
"timestamp" : 1521104923089,
"status":200,
"delete_object_count(s)": 4
}
Delete Relation
Remove all relation between parent and child.
Note: This only delete relation between parent and child and do not remove child objects.
Return: Number of deleted object counts.
Method: DELETE
URL: /v1/< application-id >/< parent-type-name >/< parent-object-id >/relation/< child-type-name >
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Request Body: {None}
Example:
Request Body: {None}
Response Body:
{
"timestamp": 1521108111690,
"status":200,
"delete_relation_count(s)": 1
}
Delete Relation With Specified Child Object
Remove relation between parent and specified child object.
Note: This API only delete relation between parent and child and do not remove child.
Method: DELETE
URL: /v1/< application-id >///relation//
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Request Body: {None}
Example:
Request Body: {None}
Response Body:
{
"timestamp": 1521108111690,
"status":200,
"delete_relation_count(s)": 1
}
By default when you get an object from Dena platform, related objects not included in the response because it may cause load performance on server or client memory. Therefore by default we get related object in a separate request or with loadRelation parameter. for getting object there are three approach:
- Find object by id
- Find objects in table
- Find objects for relation
Find object By Id
This API provides the functionality that retrieve specified object in table.
Return: Found object in data store.
Method: GET
URL: /v1/< application-id >//?loadRelation=false
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Optional Parameter
- loadRelation: Whether load relation.
Request Body: {None}
Example:
Request Body: {None}
Response Body:
{
"timestamp": 1522349375351,
"status":200,
"found_object_count(s)": 1,
"objects": [
{
"object_id": "5aaa8234bb19df25acce463e",
"object_uri": "/post/5aaa8234bb19df25acce463e",
"update_time": null,
"create_time": 1521123892553,
"field3": "javad",
"field4": "developer"
}
]
}
Find All Objects In Table
This API provides the functionality that retrieve all object of specified table data.
Return: Found object in data store.
Method: GET
URL: /v1/< application-id >/?startIndex=45&pageSize=6
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Optional Parameter
- startIndex: The start row number from which return result to client.starting from 0 and default to 0.
- pageSize: The number of records to retrieve in a single page. default to 50.
Note: For more information see Pagination section
Request Body: {None}
Example:
/v1/denaQA/post?startIndex=0&pageSize=2
Response Body:
{
"timestamp": 1522448368270,
"status":200,
"found_object_count(s)": 2,
"objects": [
{
"object_id": "5aaa11d2ecb1ef188094eed6",
"object_uri": "/post/5aaa11d2ecb1ef188094eed6",
"update_time": null,
"create_time": 1521095122362,
"field3": "javad",
"field4": "developer"
},
{
"object_id": "5aaa445ebb19df061c79f8f0",
"object_uri": "/post/5aaa445ebb19df061c79f8f0",
"update_time": null,
"create_time": 1521108062035,
"field1": "javad",
"field2": "developer"
}
]
}
Find Relation Objects
Suppose we have relation between two object for example in many-many or one-many relation and we want to retrieve related object, in this case we use this API to retrieve all objects of a relation.
Consider following Pseudo-Code:
User 1<-->* Transaction
User user = findUser(userId)
user.getTransaction() // find all transaction relation in user
Return: Found related object(s) in data store.
Method: GET
URL: /v1/< application-id >///relation/?startIndex=45&pageSize=6
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Optional Parameter
- startIndex: The start row number from which return result to client. starting from 0 and default to 0.
- pageSize: The number of records to retrieve in a single page. default to 50.
Note: for more information see Pagination section
Request Body: {None}
Example:
Request Body: {None}
Response Body:
{
"timestamp": 1522485942626,
"status":200,
"found_object_count(s)": 2,
"objects": [
{
"object_id": "5aaa095eecb1ef188094eece",
"object_uri": "/comment/5aaa095eecb1ef188094eece",
"update_time": null,
"create_time": 1521092958714,
"comment_text": "this is a comment"
},
{
"object_id": "5aaa0982ecb1ef188094eecf",
"object_uri": "/comment/5aaa0982ecb1ef188094eecf",
"update_time": null,
"create_time": 1521092994863,
"comment_text": "this is a comment 2"
}
]
}
We can count number of objects in three way:
- Object count for relation
- Object count for type
- Object count using query (TO-DO)
Object Count For Relation
Method: GET
URL: /v1/< application-id >//relation/
Request Body: None
Return Value:
{
"timestamp" : timestamp in milliseconds,
"count" : number of item retrived
}
Object Count For Type
Method: GET
URL: /v1/< application-id >/
Request Body: None
Return Value:
{
"timestamp" : timestamp in milliseconds,
"count" : number of item retrived
}
When dena platform receive request for getting objects, it limit objects count for return to client for performance reason. So we use a mechanism for pagination result to client.
Pagination using in the REST API is implemented with the startIndex
and pageSize
parameters in the objects retrieval API:
startIndex
: The start row number from which return result to client. starting from 0 and default to 0.
pageSize
: The number of records to retrieve in a single page. Minimum allowed value is 1. Default to 50.
Sample Request
/v1/< application-id >/<parent-table-name>/<parent-object-id>/relation/<relation-name>?startIndex=45&pageSize=6
/v1/< application-id >/<table-name>?startIndex=0&pageSize=2
With this API user can manage application (create, edit, find application)
Return: Created application information.
Method: POST
URL: /v1/app/register
Headers:
Content-Type : application/json
Authorization: {user token after login in Dena platform}
Body: {JSON}
Example:
Request Body:
{
"application_name": "great_app",
"creator_id": "developer@dena.com"
}
Response Body:
{
"timestamp": 1520504910721,
"status":200,
"count": 1,
"objects": [
{
"object_id": "5aa1104e99d0b323487d38a1",
"application_name": "great_app" ,
"creator_id": "developer@dena.com",
"application_id": "8a0d747e-8b4a-418a-a658-57dd995945a4",
"secret_key": "05c977f0-14be-4f2e-960d-1103fa3646bd"
}
]
}
When error occurred in service then the following json return
{
"status":400,
"error_code":"123",
"messages":["Parameter is invalid", "Relation can not be empty"]
}