Entity Collections
The entity collection node must be created using the /nodes URL. Once created, the /entities URL can be used to manipulate the content of the collection.
Get the Entity Schema
Gets the entity schema of a collection. The schema describes fields and data types:
HTTP Method: | GET |
HTTP Url: | entities/collection |
HTTP Query-Parameter: | id : Id of the collection as System.Guid |
Request Content-Type | text/xml |
Request Body | - |
Response Content-Type | text/xml |
Response Content | Schema |
Example:
GET http://localhost:8081/entities/collection?id=f9a4300a-654b-42cf-9f54-f866184b7352
Response Body:
<HumanOS.Stream>
<EntitySchema>
<Field>
<Name>FirstName</Name>
<DataType>System.String</DataType>
<IsKey>false</IsKey>
</Field>
<Field>
<Name>LastName</Name>
<DataType>System.String</DataType>
<IsKey>false</IsKey>
<DefaultValue>0</DefaultValue>
</Field>
<Field>
<Name>Id</Name>
<DataType>System.Guid</DataType>
<IsKey>true</IsKey>
</Field>
</EntitySchema>
</HumanOS.Stream>
Adding Entities
Adds entities to the collection. The call fails if an entity with its key already exists in the collection.
HTTP Method | POST |
HTTP Url: | entities/collection |
HTTP Query-Parameter: | id : Id of the collection as System.Guid |
Request Content-Type | text/xml ; text/json |
Request Body | Stream of entities to add |
Response Content-Type | text/text |
Response Content | “OK” |
Example:
POST http://localhost:8081/entities/collection?id=f9a4300a-654b-42cf-9f54-f866184b7352
Request Body:
<HumanOS.Stream>
<EntityCollection>
<Entity>
<Id>{16BB1E9F-ACFA-4D42-8DE6-3598C7C79DC6}</Id>
<LastName>Smith</LastName>
<FirstName>John</FirstName>
</Entity>
<Entity>
<Id>{41F6F2F4-F420-4457-BBCF-BD610FD39342}</Id>
<LastName>Muster</LastName>
<FirstName>Christian</FirstName>
</Entity>
</EntityCollection>
</HumanOS.Stream>
Updating Entities
Adds entities to the collection. The call fails if an entity with its key already exists in the collection.
HTTP Method | PATCH |
HTTP Url: | entities/collection |
HTTP Query-Parameter: | id : Id of the collection as System.Guid |
Request Content-Type | text/xml ; text/json |
Request Body | Stream of entities to update |
Response Content-Type | text/text |
Response Content | “OK” |
Example:
PATCH http://localhost:8081/entities/collection?id=f9a4300a-654b-42cf-9f54-f866184b7352
Request Body:
<HumanOS.Stream>
<EntityCollection>
<Entity>
<Id>{16BB1E9F-ACFA-4D42-8DE6-3598C7C79DC6}</Id>
<LastName>Smith</LastName>
<FirstName>John</FirstName>
</Entity>
<Entity>
<Id>{41F6F2F4-F420-4457-BBCF-BD610FD39342}</Id>
<LastName>Muster</LastName>
<FirstName>Christian</FirstName>
</Entity>
</EntityCollection>
</HumanOS.Stream>
Remove Entities
Removes entities from the collection.
HTTP Method | DELETE |
HTTP Url: | entities/collection |
HTTP Query-Parameter: | id : Id of the collection as System.Guid |
Request Content-Type | text/xml ; text/json |
Request Body | Stream of entities ids |
Response Content-Type | text/text |
Response Content | “OK” |
Example:
DELETE http://localhost:8081/entities/collection?id=f9a4300a-654b-42cf-9f54-f866184b7352
Request Body:
<HumanOS.Stream>
<EntityCollection>
<Entity>
<Id>{16BB1E9F-ACFA-4D42-8DE6-3598C7C79DC6}</Id>
</Entity>
<Entity>
<Id>{41F6F2F4-F420-4457-BBCF-BD610FD39342}</Id>
</Entity>
</EntityCollection>
</HumanOS.Stream>
Get All Entities
Gets all entities of an entity collection:
HTTP Method | GET |
HTTP Url: | entities/all |
HTTP Query-Parameter: | id : Id of the collection as System.Guid |
Request Content-Type | - |
Request Body | - |
Response Content-Type | text/xml ; text/json |
Response Content | Entity stream |
Example:
GET http://localhost:8081/entities/all?id=f9a4300a-654b-42cf-9f54-f866184b7352
Query Entities
Queries a subset of the entity collection
HTTP Method: | GET |
HTTP Url: | entities/query |
HTTP Query-Parameter: | id : Id of the collection as System.Guid |
Request Content-Type | text/xml |
Request Body | Query and filter criteria |
Response Content-Type | text/xml |
Response Content | Entity stream |
Example:
POST http://localhost:8081/entities/query?id=f9a4300a-654b-42cf-9f54-f866184b7352
Request Body:
<HumanOS.Stream>
<EntityQuery>
<Expression type="binary" op="AND">
<Expression type="unary" op="NOT">
<Expression type="field" name="HasChildren"/>
</Expression>
<Expression type="binary" op="EQ">
<Expression type="field" name="FirstName"/>
<Expression type="const" datatype="System.String">Hans</Expression>
</Expression>
</Expression>
</EntityQuery>
</HumanOS.Stream>
This is translated to: n => !n.HasChildren && n.FirstName == "Hans"
Response Body:
<HumanOS.Stream>
<EntityCollection>
<Entity>
<Id>{16BB1E9F-ACFA-4D42-8DE6-3598C7C79DC6}</Id>
<LastName>Muster</LastName>
<FirstName>Hans</FirstName>
<HasChildren>false</HasChildren>
</Entity>
</HumanOS.Stream>
Query Language
The query language accepts only Boolean expressions.
Expression :== BinaryExpression | UnaryExpression | Constant | Field
BinaryExpression:== <Expression type=”binary” op=”[Binary_Operation]”>
[Expression]
[Expression]
</Expression>
UnaryExpression:== <Expression type=”unary” op=”[Unary_Operation]”>
[Expression]
</Expression>
Constant :== <Expression type=”const” datatype=”[DataType]”>
[Value]
</Expression>
Field :== <Expression type=”field” name=”[Name]”/>
Binary_Operation:== “EQ” | “NEQ” | “GT” | “LT” | “LE” | “GE” | “AND” | “OR”
Unary_Operation:== “NOT”
Value:== Number | Text
DataType:== {C# System Type}
Name:== {Field name}
Example 1:
n => n.FirstName == “John”
<HumanOS.Stream>
<EntityQuery>
<Expression type="binary" op="EQ">
<Expression type="field" name="FirstName"/>
<Expression type="const" datatype="System.String">John</Expression>
</Expression>
</EntityQuery>
</HumanOS.Stream>
Example 2:
n => n.Age > 39
<HumanOS.Stream>
<EntityQuery>
<Expression type="binary" op="GT">
<Expression type="field" name="Age"/>
<Expression type="const" datatype="System.Int32">39</Expression>
</Expression>
</EntityQuery>
</HumanOS.Stream>
Example 3:
n => n.Age <= 40 || n.LastName == “Smith”
<HumanOS.Stream>
<EntityQuery>
<Expression type="binary" op="OR">
<Expression type="binary" op="LE">
<Expression type="field" name="Age"/>
<Expression type="const" datatype="System.Int32">40</Expression>
</Expression>
<Expression type="binary" op="EQ">
<Expression type="field" name="LastName"/>
<Expression type="const" datatype="System.String">Smith</Expression>
</Expression>
</Expression>
</EntityQuery>
</HumanOS.Stream>