Web Linking, Profiles etc

瀏覽次數:37 次
跳到第一則未讀訊息

Jack Whelpton

未讀,
2017年5月9日 下午4:44:302017/5/9
收件者:Mason media type
Hi all,

I'm currently working on an API design using Mason; after a few dalliances with other media types it's been a pleasant compromise between a full set of REST affordances and sending users unfamiliar with those concepts running in terror. I had a few questions, though; apologies if these have already been answered.

1. Web linking (RFC 5988)
RFC 5988, which I've previously used in custom media types to define links within an API, adds five additional properties to its link definition: "hreflang", "media", "title", "title*" and "type". As far as I can tell the mapping of these to @control properties is:

hreflang -> ?
media -> CSS specific, of limited use for a web API
title -> title
title* -> exists predominantly to allow encoding of non-ASCII characters in HTTP headers; not required when links are in the body
type -> output

The only useful property I can't find a direct mapping for is "hreflang", which I have found to be useful when presenting multilingual content that can be updated independently. Is there an equivalent in Mason?

2. Multiple links
I've occasionally found it useful to present multiple links with the same relation type. This has normally been for fairly loose link relation types, like "related", and the client will use the "title" property to offer a menu to a user at that point. I notice that Mason offers the "alt" property; is that the recommended approach here? Often these scenarios have no clearly-identifiable "primary" element, so in those cases I imagine I would have to arbitrarily nominate one.

To return to the multilingual case, another example might be a set of control elements varying only in the language of the target resource.

3. Profiles
The Mason media type doesn't appear to be support a "profile" media type parameter; could this be added easily? I've typically found this to be one of the more powerful ways to version or specialize an API response without overloading concepts such as URI etc. I've been reading Mike Amundsen's Restful Web APIs book recently, and was pleasantly reassured to see him promoting a similar approach.

Cheers,

Jack.

Jørn Wildt

未讀,
2017年5月10日 凌晨2:47:562017/5/10
收件者:mason-me...@googlegroups.com
Hi Jack

Nice to know that Mason is actually used out there :-) Thanks for the feedback.

1) Mason has no language support. You need to encode that yourself somehow. Can you give a more detailed example of how you would use it?

2) You are right about the use of "alt" in links. And, yes, I understand that none of the "related" links are supposed to be more primary than the others. Think of it as a list instead with the primary simply being the first in the list.

3) Profiles are not supported. It could make sense to add it. You can always just add your own JSON property value named "MyProfileIndicator" (or what ever else) and tell your client devs how to understand it.

I have the feeling that adding profiles would require me to explain how profiles are used as they somehow say something about how the payload is to be interpreted - and how would such a format look? Maybe just plain human readable text? And would you allow more than one profile to be used? Does that mean "multiple inheritance"? Seems a bit like RDF's "rdf:type" property. Would you allow profiles to be used in multiple nested levels of the data - indicating the profile of sub-structures in the data? Profiles can even be encoded in links with special link relations :-)

/Jørn

--
You received this message because you are subscribed to the Google Groups "Mason media type" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mason-media-type+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jørn Wildt

未讀,
2017年5月10日 凌晨4:53:492017/5/10
收件者:mason-me...@googlegroups.com
Hi Jack

One more comment ... Mason was designed for machine-to-machine integrations where UI is irrelevant. The few Title properties and such are there for debugging mostly - not to create a useful UI.

So for instance, when you say "and the client will use the "title" property to offer a menu to a user at that point", you have wandered into uncharted territory for Mason :-) If that list is important you should encode the UI using other, custom, JSON property values designed for that purpose.

The same goes for the use of "hreflang" - it indicates that you are building a UI directly from Mason which is not a goal for Mason.

At some time I considered inventing a style sheet language for Mason along the lines of XML style-sheets - which is more of a templating system. With this you could serve data machine readable with Mason and then apply a stylesheet of some sort to create the UI for the data. But I never dived into that idea. Today you could probably use one of the many JSON/Javascript/single-page-app web-templating-frameworks for the purpose.

/Jørn

On Tue, May 9, 2017 at 10:44 PM, Jack Whelpton <j.whe...@outlook.com> wrote:

--

Jack Whelpton

未讀,
2017年5月23日 下午1:58:362017/5/23
收件者:mason-me...@googlegroups.com

Hi Jørn,

 

Thanks for the reply, sorry it’s taken me a couple of weeks to get back… you know how the day job can be sometimes! As a little background on the project in hand, I’m working on the API layer for a catalog system. This is a problem I’ve tackled before, often taking a slightly different tack each time; previously I’d been worked with a custom media type, but this time around I was keen to standardize a little. The integrations are initially a little unclear, but I’ve tended to use the catalog maintenance UI as a good proving ground for the API design; one of the first integrations that you can envisage is an internal editing tool. I’m not, however, trying to burden the API with presentation concerns.

 

Even within such a limited use case, I’ve found hypermedia affordances handy: for example, the API can provide links from “search results” to details of an individual product etc.

 

That briefest of explanations does at least provide enough for me to leap into your questions:

 

1)      Mason has no language support. You need to encode that yourself somehow. Can you give a more detailed example of how you would use it?

 

Multi-lingual support is pretty subtle. We maintain individual “translations” of product information, which can be updated independently. The Accept-Language header isn’t designed for targeting different resources for updating etc., so these translations get their own URIs, something like:

 

/product/{id}/language/{language}

 

e.g.:

 

/product/1/language/en-us

 

The Accept-Language header is used to determine the language of metadata: names of product attributes, the name of the product’s category/type/genre etc.

 

I can see a use for exposing a list of all the translations available for a product, via a URI something like:

 

/product/1/languages

 

Previously I’ve returned this as a list of links of a custom type, with a different hreflang. I’m guessing something like:

 

{

  "@namespaces": { "cat": { "name": "http://rels.example.org/" } },

  "@controls": {

    "cat:product": {

      "href": "/product/1/language/en",

      "hreflang": "en",

      "alt": [

        { "href": "/product/1/language/fr", "hreflang": "fr" },

        { "href": "/product/1/language/ja", "hreflang": "ja" },

        { "href": "/product/1/language/en-us", "hreflang": "en-us" }

      ]

    }

  }

}

 

One alternative approach would be to create minimal product representations, bearing the language property and a canonical link, something like:

 

{

  "@namespaces": { "cat": { "name": "http://rels.example.org/" } },

  "translations": [

    {

      "@controls": { "canonical": "/product/1/language/fr" },

      "language": "fr"

    },

    {

      "@controls": { "canonical": "/product/1/language/ja" },

      "language": "ja"

    },

    {

      "@controls": { "canonical": "/product/1/language/en-us" },

      "language": "en-us"

    }

  ]

}

 

2)      You are right about the use of "alt" in links. And, yes, I understand that none of the "related" links are supposed to be more primary than the others. Think of it as a list instead with the primary simply being the first in the list.

 

Cool, I just wanted to check that wasn’t a perversion of the spec. The example above shows this in action.

 

3)      Profiles are not supported. It could make sense to add it. You can always just add your own JSON property value named "MyProfileIndicator" (or what ever else) and tell your client devs how to understand it.

 

I was always planning on doing this: it doesn’t need a custom JSON property, as the “profile” link relation is defined in the IANA link registry. Here’s how I’ve used it before:

 

{

  "@controls": {

    "profile": {

      "href": "http://profiles.example.org?resource=product&name=canonical&version=1",

    }

  }

}

 

I can thus use this to handle versioning when absolutely required, on a per-resource basis, and I can offer lighter-weight payloads (e.g. name=”search-result”). The URI provides me somewhere to hang documentation for the client developer, usually just human-readable text.

 

However, for this to work for versioning I really want to support a client sending a request for a specific profile, thus:

 

Accept: application/vnd.mason+json;profile=http://profiles.example.org?version=1

 

The book I’m currently reading suggests, as a workaround for media types that don’t support this,

 

Link: <http://profiles.example.org?version=1>; rel=profile

 

But this seems clunkier/less expressive to me.

 

Interesting that you mention multiple inheritance; I’ve done something similar before, but not exactly using profiles. I provided documentation that said the IANA link relation “collection” would always return results that adhere to the “page” profile, and I’d have links like:

 

{

  "@namespaces": { "cat": { "name": "http://rels.example.org/" } },

  "@controls": {

    "cat:product collection": {

      "href": "/product/1/languages"

    }

  }

}

 

I don’t know if there’s a way to do this in Mason… create a single link with multiple types?

 

This might be an argument for the Link approach above, as you could easily specify multiple profiles:

 

Link: <http://profiles.example.org?resource=product&version=1>; rel=profile

Link: <http://profiles.example.org?resource=page>; rel=profile

 

Incidentally, on the subject of pagination properties, is the @meta block the best place for these (currentPage, pageCount, pageSize, totalCount)? I’m guessing so.

 

I think that’s most of my musings for now… sorry for the mass of verbiage, but this is an interesting area and will help me understand how best to leverage Mason (or, indeed, if something else would be more appropriate).

 

Cheers,

 

Jack.

--

To unsubscribe from this group and stop receiving emails from it, send an email to mason-media-ty...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

 

--

You received this message because you are subscribed to the Google Groups "Mason media type" group.

To unsubscribe from this group and stop receiving emails from it, send an email to mason-media-ty...@googlegroups.com.

回覆所有人
回覆作者
轉寄
0 則新訊息