3

I want to use a REST API with hypermedia constraint to drive my UI. That is, depending on "possible next states" for the resources I fetch, I want to adapt my UI for this. I'm quite new to UI dev on the web so I wonder if there is any special considerations I need to care about here?

Lets say I have a resource that looks like this:

{
   href: "..",
   orderDate: date..,
   details: {
       href : "..",
       items: [..],
   }  
   links: [
   placeOrder : {
        href : "...",
        method : "post"
   },
   cancelOrder : {
        href : "...",
        method : "delete"
   }]
}

Would the above links approach be valid within the context of HATEOAS ? In a perfect world I guess one should just know about HTTP verbs for actions on the resource but if I want to let the UI know about what can be done to the resource, how do I do this in an idiomatic way?

What I mean is, the same kind of resource can have different "next possible state" depending on current status. And the UI needs to know about this. Should the UI examine what links are available on the resource or how do I do this?

4

2 に答える 2

2

はい、正確に。UI は、提示されたリンク関係に合わせて完全にコーディングする必要があります。リレーションをフォローできない場合、応答のリンク コレクションでリレーションを返すべきではありません。これは、現在の状態を駆動するだけでなく、UI がアクセス制御ルールを計算しようとする負担がかからないことも意味します。

于 2013-11-16T20:44:56.920 に答える