Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions drafts/use-cases/0.intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ These would be:
"@id": "hydra:title",
"@type": "xsd:string"
},
"action": {
"@id": "hydra:action",
"@type": "@id"
},
"operation": {
"@id": "hydra:operation",
"@type": "@id"
},
"target": {
"@id": "hydra:target",
"@type": "@id"
},
"method": {
"@id": "hydra:method",
"@type": "xsd:string"
Expand Down Expand Up @@ -101,13 +109,6 @@ These would be:
"@id": "hydra:totalItems",
"@type": "xsd:int"
},
"search": {
"@id": "hydra:search",
},
"Event": {
"@id": "schema:Event",
"@type": "@id"
},
"eventName": {
"@id": "schema:name",
"@type": "xsd:string"
Expand Down
36 changes: 24 additions & 12 deletions drafts/use-cases/1.1.security-considerations.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ There are several possibilities here. One of them would be to use a *@graph* not
"property": "rdf:type",
"object": "schema:Event"
},
"operation": {
"@type": ["Operation", "schema:CreateAction"],
"action": {
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "Create new event",
"method": "POST",
"expects": "schema:Event"
"operation": {
"@type": "Operation",
"method": "POST",
"expects": "schema:Event",
"target": "/api/events"
}
}
},
{
Expand All @@ -40,11 +44,15 @@ There are several possibilities here. One of them would be to use a *@graph* not
"property": "rdf:type",
"object": "schema:Person"
},
"operation": {
"@type": ["Operation", "schema:CreateAction"],
"action": {
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "Create new person",
"method": "POST",
"expects": "schema:Person"
"operation": {
"@type": "Operation",
"method": "POST",
"expects": "schema:Person",
"target": "/api/people"
}
}
},
{
Expand All @@ -55,11 +63,15 @@ There are several possibilities here. One of them would be to use a *@graph* not
"property": "rdf:type",
"object": "schema:Place"
},
"operation": {
"@type": ["Operation", "schema:CreateAction"],
"action": {
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "Create new venue",
"method": "POST",
"expects": "schema:Place"
"operation": {
"@type": "Operation",
"method": "POST",
"expects": "schema:Place",
"target": "/api/venues"
}
}
}
]
Expand Down
36 changes: 24 additions & 12 deletions drafts/use-cases/1.entry-point.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ HTTP 200 OK
"property": "rdf:type",
"object": "schema:Event"
},
"operation": {
"@type": ["Operation", "schema:CreateAction"],
"action": {
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "Create new event",
"method": "POST",
"expects": "schema:Event"
"operation": {
"@type": "Operation",
"method": "POST",
"expects": "schema:Event",
"target": "/api/events",
}
}
},
{
Expand All @@ -61,11 +65,15 @@ HTTP 200 OK
"property": "rdf:type",
"object": "schema:Person"
},
"operation": {
"@type": ["Operation", "schema:CreateAction"],
"action": {
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "Create new person",
"method": "POST",
"expects": "schema:Person"
"operation": {
"@type": "Operation",
"method": "POST",
"expects": "schema:Person",
"target": "/api/people"
}
}
},
{
Expand All @@ -76,11 +84,15 @@ HTTP 200 OK
"property": "rdf:type",
"object": "schema:Place"
},
"operation": {
"@type": ["Operation", "schema:CreateAction"],
"action": {
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "Create new venue",
"method": "POST",
"expects": "schema:Place"
"operation": {
"@type": "Operation",
"method": "POST",
"expects": "schema:Place",
"target": "/api/venues"
}
}
}
]
Expand Down
12 changes: 8 additions & 4 deletions drafts/use-cases/3.1.extensions-considerations.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ Again, named graphs would come in handy in this situation, i.e.:
"@graph": [
{
"@id": "/api/events",
"operation": [
"action": [
{
"@type": ["Operation", "schema:CreateAction"],
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "Create new event",
"method": "POST",
"expects": "schema:Event"
"operation": {
"@type": "Operation",
"method": "POST",
"expects": "schema:Event",
"target": "/api/events"
}
}
],
"member": [
Expand Down
73 changes: 35 additions & 38 deletions drafts/use-cases/5.1.creating-event-with-put.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,22 @@ var event = {
'startDate': '2017-04-19',
'endDate': '2017-04-19'
};
var templateVariables = {
slug: [
'meeting',
'with-will'
]
};

var client = new HydraClient();
var memberTemplate = client.get('http://example.com/events').memberTemplate;
var operation = memberTemplate
.getOperationsOfType('http://schema.org/CreateAction')
.thatExpect('http://schema.org/Event')
.first();

const operationWithTargetExpanded = operation.expandTarget(templateVariables);
client.invoke(operationWithTargetExpanded, event);
client.usingApi("http://example.com/")
.findCollectionWith({
property: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
object: "http://schema.org/Event"
})
.invoke('http://schema.org/CreateAction')
.whichExpects('http://schema.org/Event')
.withData(event)
.getResult();
```


## Details

To create an `Event` using `PUT`, the collection resource has to be linked to the actual target of the operation.
To create an `Event` using `PUT`, the collection resource has to advertise an action with a target for the operation.
The target of the operation can either be a concrete URL or an `IriTemplate` as shown in the example above. Concrete URLs are
out of scope for this use case and might be discussed at a later point in a separate use case document.

Expand All @@ -66,39 +60,42 @@ HTTP 200 OK
},
"totalItems": 0,
"members": [ ],
"memberTemplate": {
"@type": "IriTemplate",
"template": "http://example.com/api/event{/slug*}",
"variableRepresentation": "BasicRepresentation",
"mapping": [
{
"@type": "IriTemplateMapping",
"variable": "slug",
"property": "schema:name",
"required": true
}
],
"operation": [
{
"@type": [ "Operation", "schema:CreateAction" ],
"title": "Create new event",
"action": {
"@type": ["schema:AddAction", "schema:CreateAction"],
"title": "create an event and add to collection",
"operation": {
"@type": "Operation",
"method": "PUT",
"expects": "schema:Event"
}
]
"expects": "schema:Event",
"target": {
"@type": "IriTemplate",
"template": "http://example.com/api/events/{uuid}",
"variableRepresentation": "BasicRepresentation",
"mapping": [
{
"@type": "IriTemplateMapping",
"variable": "uuid",
"property": "schema:uuid",
"required": true
}
]
}
}
}
}
```

We will assume that hydra client understands `schema:uuid` and will automaticaly generate [UUID v4](https://tools.ietf.org/html/rfc4122#section-4.4) and substituted variable in IRI template which maps to it.

Upon executing the snippet above the following request will be sent to the server:

```http
PUT /api/event/meeting/with-will HTTP/1.1
PUT /api/events/f94ebb70-bf47-4713-8486-386262ca2a12 HTTP/1.1
```

```json
{
"@context": "/api/context.jsonld",
"@context": "http://example.com/api/context.jsonld",
"@type": "schema:Event",
"eventName": "My brand new event",
"eventDescription": "Hope it will work",
Expand Down Expand Up @@ -136,7 +133,7 @@ In such case it would respond with `HTTP/1.1 412 Precondition Failed` status.

### Advertising connection between collection and created event

The `schema:CreateAction` operation is attached to collection's `memberTemplate` which informs the client that the newly
The `schema:AddAction` operation is advertised on the collection itself, which informs the client that the newly
created event will become part of the collection, i.e. it's `"member"` property. However, such operation can have an effect on
more that one related resource. Building upon this example, in a more elaborate setting creating a personal event could also
add that event to the events collection of all participants.
Expand Down
23 changes: 11 additions & 12 deletions drafts/use-cases/5.creating-new-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ var event = {
"startDate": "2017-04-19",
"endDate": "2017-04-19"
};
var client = new HydraClient();
var operation = client.get("http://example.com")
.getApiDocumentation()
.getEntryPoint()
.getCollection({
property: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
object: "http://schema.org/Event"
})
.getOperationOfType('http://schema.org/CreateAction');
client.invoke(operation, event);
client.usingApi("http://example.com/")
.findCollectionWith({
property: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
object: "http://schema.org/Event"
})
.invoke('http://schema.org/CreateAction')
.whichExpects('http://schema.org/Event')
.withData(event)
.getResult();
```


Expand All @@ -51,7 +50,7 @@ POST /api/events

```json
{
"@context": "/api/context.jsonld",
"@context": "http://example.com/api/context.jsonld",
"@type": "schema:Event",
"eventName": "My brand new event",
"eventDescription": "Hope it will work",
Expand All @@ -62,7 +61,7 @@ POST /api/events

```http
HTTP 201 Created
Location: /api/events/2
Location: /api/events/173a6d5b-e9fc-43d7-a19a-215a06d37f31
```

Brand new event should be now added to the calendar.
Expand Down
16 changes: 10 additions & 6 deletions drafts/use-cases/6.updating-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ HTTP 200 OK
"eventDescription": "Hope it will work",
"startDate": "2017-04-19",
"endDate": "2017-04-19",
"operation": [
{
"@type": ["Operation", "schema:ReplaceAction"],
"title": "Update an existing event",
"method": "PUT",
"expects": "schema:Event"
"action": [
{
"@type": "schema:ReplaceAction",
"title": "Update an existing event",
"operation": {
"@type": "Operation",
"method": "PUT",
"expects": "schema:Event",
"target": "/api/events/1"
}
}
]
}
```
Expand Down
Loading