Re: [apps-discuss] JSON-Home widget example

Mark Nottingham <mnot@mnot.net> Tue, 09 April 2013 06:52 UTC

Return-Path: <mnot@mnot.net>
X-Original-To: apps-discuss@ietfa.amsl.com
Delivered-To: apps-discuss@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 4770821F8F24 for <apps-discuss@ietfa.amsl.com>; Mon, 8 Apr 2013 23:52:07 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -105.016
X-Spam-Level:
X-Spam-Status: No, score=-105.016 tagged_above=-999 required=5 tests=[AWL=-2.917, BAYES_00=-2.599, GB_ABOUTYOU=0.5, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gtL1eclu8ec3 for <apps-discuss@ietfa.amsl.com>; Mon, 8 Apr 2013 23:52:04 -0700 (PDT)
Received: from mxout-08.mxes.net (mxout-08.mxes.net [216.86.168.183]) by ietfa.amsl.com (Postfix) with ESMTP id 2CAFC21F8E7B for <apps-discuss@ietf.org>; Mon, 8 Apr 2013 23:52:03 -0700 (PDT)
Received: from [192.168.1.80] (unknown [118.209.42.8]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id 319CF509B5; Tue, 9 Apr 2013 02:52:00 -0400 (EDT)
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\))
From: Mark Nottingham <mnot@mnot.net>
In-Reply-To: <E30D6548-732B-4996-8363-A699A487B65B@nordsc.com>
Date: Tue, 9 Apr 2013 16:51:56 +1000
Content-Transfer-Encoding: quoted-printable
Message-Id: <51DCC678-F1A5-4877-8168-260DE09244E5@mnot.net>
References: <E30D6548-732B-4996-8363-A699A487B65B@nordsc.com>
To: Jan Algermissen <jan.algermissen@nordsc.com>
X-Mailer: Apple Mail (2.1503)
Cc: "apps-discuss@ietf.org" <apps-discuss@ietf.org>
Subject: Re: [apps-discuss] JSON-Home widget example
X-BeenThere: apps-discuss@ietf.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: General discussion of application-layer protocols <apps-discuss.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/apps-discuss>, <mailto:apps-discuss-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/apps-discuss>
List-Post: <mailto:apps-discuss@ietf.org>
List-Help: <mailto:apps-discuss-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/apps-discuss>, <mailto:apps-discuss-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Apr 2013 06:52:15 -0000

Hi Jan,

This isn't really specific to home; it's about collections and link relations. It came up some when we were doing 5988, IIRC.

There are a couple of ways of dealing with it. 

One would be to have a "collection" link relation and then put a parameter on it that says what it contains.

E.g., as a HTTP header, it would be:
  Link: </widgets>; rel="collection"; contains="http://example.org/rel/widget"

However, in JSON Home, this becomes:

     "collection": {
        "href": "/widgets/",
        "contains": "http://example.org/rel/widget"
      },
      "http://example.org/rel/widget": {
        "href-template": "/widgets/{widget_id}",
        "href-vars": {
          "widget_id": "http://example.org/param/widget"
        },
        ...
      }

which isn't great, because you can then have only one collection type in your API! It also means that a *lot* of identifying information is lost from the link relation type. If we allowed multiple collection relation types to be defined (for example, by making its value an array of objects), it would introduce an extra layer of dispatch, which isn't great.

If you turn that inside-out, you might end up with something like:

      "http://example.org/rel/widget": {
        "href-template": "/widgets/{widget_id}",
        "href-vars": {
          "widget_id": "http://example.org/param/widget"
        },
        "container": "/widgets/"
      }

This is succinct, but I'm wary, because the container is "hidden" inside the widget type, and you now need to *very* precisely define the semantics of "container"; if you want to vary from it even a little bit, you're out of luck, because there's no space for adorning it with hints, etc. This approach also precludes mixing different things in the same container (at least obviously).

The way I look at it, what you're asking for here is syntactic sugar. In English, we have separate names for "jar" and "candy" because they're separate things, even though they're often used together.

While it's tempting to define the primitive "jar of candy", I don't want to *start* there, because it'll severely limit the expressiveness of the format, and create awkward special/corner cases.

So, I suspect that we'll always need two relation types to accurately talk about things vs. containers of things. 

That's not to say that we don't need something here, of course; IIRC there is a TODO in the spec for precisely this. I'm just not quite at the point where I know what it looks like. If I had to take a stab now, it'd be something like:

     "http://example.org/rel/widget": {
        "href": "/widgets/",
        "contains": "http://example.org/rel/widget"
      },
      "http://example.org/rel/widget": {
        "href-template": "/widgets/{widget_id}",
        "href-vars": {
          "widget_id": "http://example.org/param/widget"
        },
        ...
      }

Does that make sense? 

Cheers,






On 08/04/2013, at 9:11 PM, Jan Algermissen <jan.algermissen@nordsc.com> wrote:

> Hi Mark,
> 
> curious about your opinion on the following.
> 
> The example you provide in the draft[1] troubles me a bit since a real-life, similar case made me look at it from a different angle.
> 
> 
>    "http://example.org/rel/widgets": {
>         "href": "/widgets/"
>       },
>       "http://example.org/rel/widget": {
>         "href-template": "/widgets/{widget_id}",
>         "href-vars": {
>           "widget_id": "http://example.org/param/widget"
>         },
>         ...
>       }
> 
> What we have here is sort of a standard pattern for making available 'a bag of things' via HTTP.
> 
> For example, a bunch of orders can be straight forward exposed as
> 
>  /orders
> 
> and knowing that
> 
>  "http://example.org/rel/orders" : { "href" : "/orders" }
> 
> pretty much implies something like /orders/{orderId}, including the idea that adding an order is likely done with a POST to /orders and that editing an order is (maybe) achieved with PUT/PATCH/DELETE.
> 
> What troubles me is that JSON Home currently makes it necessary to define two link relations to cover a standard (in a sense) use case that could be covered with just one link relation. Or, in other words, the two link rels somehow semantically overlap, yet demand two 'specifications'. Think in terms of violating DRY.
> 
> Can't think of an improvement that does not introduce the 'pattern' into the spec, but I am nevertheless much interested in your view.
> 
> Maybe an optional {widget_id} and one rel with appropriate definition does the trick already, but hard to seperate the hints. Dunno...
> 
> Jan
> 
> [1] http://tools.ietf.org/html/draft-nottingham-json-home-02
> 

--
Mark Nottingham   http://www.mnot.net/