Re: How to GET a cup of coffee - Restbucks with Hydra

Hi,


Am 11. März 2015 22:45:14 schrieb Gregg Kellogg <gregg@greggkellogg.net>:

> > On Mar 11, 2015, at 2:00 AM, Dietrich Schulten <ds@escalon.de> wrote:
> >

>
> I didn't look closely at http://schema.org/orderedItem to see the range as 
> Order rather than the Domain, in which case you'd probably want the following:
>
> {
>   "@context": ["http://schema.org", "http://www.w3.org/ns/hydra/core", {
>     "@vocab": "http://schema.org/",
>     "hydra:object": {"@type": "@id"},
>     "hydra:property": {"@type": "@vocab"}
>   }],
>   "name": "Latte Macchiato",
>   "hydra:collection": [
>     {
>       "@type": "hydra:Collection",
>       "@id": "http://example.com/orders",
>       "hydra:manages": {
>         "hydra:property": "orderedItem",
>         "hydra:object": "http://example.com/latte-1"
>       },
>       "hydra:operation": {
>         "hydra:method": "POST",
>         "hydra:expects": {
>           "hydra:supportedProperty": [
>             {
>               "@type": "PropertyValueSpecification",
>               "hydra:property": "productID",
>               "hydra:required": true,
>               "defaultValue": "latte-1",
>               "readOnlyValue": true
>             }
>           ]
>         }
>       }
>     }
>   ]
> }

But based on the "mechanics" of the manages block this

>       "hydra:manages": {
>         "hydra:property": "orderedItem",
>         "hydra:object": "http://example.com/latte-1"
>       },

would say that the collection items (the products) are the subject and 
/latte1 is the object in each triple.

I.e. the product /latte1 is an orderedItem of /latte1 - not what I mean to 
say either.

What I should say based on the domainIncludes and rangeIncludes of 
:orderedItem is that /latte1 is an orderedItem of an :Order:

</orders/42> :orderedItem </latte1>

Unfortunately, order #42 does not exist yet, so I cannot identify it. What 
do you think of the following solution which uses a blank node:

       "hydra:manages": {
         "hydra:property": "orderedItem",
         "hydra:subject": {"@type": "Order" }
       }

By the mechanics of the manages block, this says that the collection 
relates products as orderedItems to an Order which cannot be identified at 
the moment. That is exactly the situation. The Order will be created 
because we post the product.

It is also better than relating the products to the store, because 
orderedItem has domainIncludes Order, not CafeOrCoffeeshop.

Would it be legitimate to use a blank node as the value of hydra:subject?

>
> It seems the the result of this operation should add a product to an order, 
> rather than a person (referenced via hydra:object) and result in a 
> relationship from the Order to the Product rather than a Customer to the Order:
>
> {
>   "@type": "Order",
>   "orderedItem": {
>     "@type": "Product",
>     "@id": "latte-1"
>   },
>   "productID": "latte-1"
> }
>
> This seems to make the "productID" property (not defined in schema.org 
> anyway) redundant?

Actually, productID is defined in schema.org, mind the uppercase: 
http://schema.org/productID. The good part is, the server can prescribe 
whatever it likes as expected request. It could prescribe the @id, a 
product name, the schema:productID or anything else it needs to handle the 
content of the POST properly. Sometimes if you POST, you do not have an 
@id. So the content of the request body is up to the server.

I should make this "freedom of the server" more clear in the Wiki article.

Best regards,
Dietrich

Received on Saturday, 14 March 2015 14:01:52 UTC