RE: Extend describing operations

Hi,

On 13 Mrz 2016 at 16:50, Tomasz Pluskiewicz wrote:
> I've been thinking about this for some time. Consider a blogging
> platform, where I can POST a blog post
> 
> HTTP/1.1 POST /blog
> 
> { "title": "My blog post", "text": "some markdown maybe"  }
> 
> But instead of getting published immediately, it could create a draft
> at, say /drafts/my-blog-post.
> 
> Now how would I use Hydra to model an operation, which publishes the
> draft? I would think of a POST operation like
> 
> HTTP/1.1 POST /blog/published
> 
> { "@id": "/drafts/my-blog-post" }

I agree with Karol and Dietrich that this probably wouldn't be the cleanest design.


> Unfortunately I don't see how that would be possible. This raises a
> number of questions:
> 
> 1. Should it be possible to define complete or partial body of an
> operation in addition to the "expects" property? I'm thinking
> 
> {
>    "operation": [
>      "expects": "BlogPost",
>      "body": {
>        "title": "New blog post"
>      }
>    ]
> }

That would just be a different "expects" I guess. Anyhow, the problem is that we currently can't express "give me the URL of a resource (out of that set of valid resources).


> If the "expects" was absent, the "body" would be the complete request to
> be sent by the client. Otherwise it could serve as an initial
> representation to create the UI/form.
> 
> 2. Should it be possible to have an operation not on self but on another
> resource. This is what I could write to describe the publish operation
> above:
> 
> {
>    "operation": [
>      "@type": "PublishOperation",
>      "url": "/blog/published",
>      "body": { "@id": "/drafts/my-blog-post" }
>    ]
> }

Yes, we should make that possible. We just need to find a way to relate the resource to the operation then... the simplest solution would be to leverage schema.org/action for that.


> I'm feeling kind of like the "/blog/published" resource should be a link
> with it's own operation. I'm still not sure how what to do about the
> predefined "body".

The simplest approach would be to add a "status" property to the blog post. An alternative would be to have a collection of published blog posts (as you seem to have) and then just link the two resources (there exists an standards track draft for a HTTP Link/Unlink methods [1]).


Cheers,
Markus


[1] https://tools.ietf.org/html/draft-snell-link-method-12


--
Markus Lanthaler
@markuslanthaler

Received on Tuesday, 5 April 2016 20:25:27 UTC