Embedding non JSON content

91 views
Skip to first unread message

Michael Tiller

unread,
Jun 5, 2017, 5:40:50 PM6/5/17
to Siren Hypermedia
I was mulling over a use case that involved trying to bundle content that wasn't JSON inside the entities (just to minimize the chattiness of the API).  For our purposes, image this is an image and we want to bundle it in a response.  The question is, what is the best way to do it.  The non-embedded version might look like:

  "links": [
    { "rel": [ "image" ], "href": "https://pp.vk.me/c618820/v618820936/7b6f/AsFMEleEiBY.jpg" }
  ]

Now, if I wanted to embed things, I could use the data scheme, as such:

  "links": [
    { "rel": [ "image" ], "href": "data:image/jpeg;base64,..." }
  ]

Seems simple.  But I was wondering if it would be more consistent to put this under entities, e.g.,

  "entities": [
    { "rel": [ "image" ], "href": "data:image/jpeg;base64,..." }
  ]

Or perhaps even better to include multiple links to give clients a chance to record the true URL for future reference.

  "entities": [
    {
      "rel": [ "image" ],
      "links": [
        { "rel": [ "self" ], "href": "https://pp.vk.me/c618820/v618820936/7b6f/AsFMEleEiBY.jpg" },
        { "rel": [ "data" ], "href": "data:image/jpeg;base64,..." }
      ]
    }
  ]


Another possibility, which I don't like at all but would be interested if anybody advocates for it, would be:

  "entities": [
    {
      "rel": [ "image" ],
      "links": [
        { "rel": [ "self" ], "href": "https://pp.vk.me/c618820/v618820936/7b6f/AsFMEleEiBY.jpg" }
      ],
      "properties": {
        "content-type": "image/jpeg",
        "data": "..."
      }
    }
  ]

Obviously, all are legal Siren.  I'm just wondering if anybody sees any particular compelling pros and cons to any of these.  Using "links" plus a single "data:" URI seems good enough to me.  I'm just wondering if it is reasonable for clients to handle data: URIs seamlessly.

--
Mike

Dmitry Pavlov

unread,
Jul 20, 2017, 3:46:00 PM7/20/17
to siren-hy...@googlegroups.com
Hi Mke,
I don't see any issues with href's containing embedded data, you just need to be ready that mostly browsers would support them natively.
As for multiple approaches, I'd say that all depends on your requirements. Personally I think that simple link and and entity containing link is mostly interchangeable and that depends on your domain (e.g. if image is really some subentity or not). 

--
You received this message because you are subscribed to the Google Groups "Siren Hypermedia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to siren-hypermedia+unsubscribe@googlegroups.com.
To post to this group, send email to siren-hypermedia@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/siren-hypermedia/2830aa29-994c-4a48-8f7b-57b0c436250e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
С уважением,
Дмитрий Павлов
Reply all
Reply to author
Forward
0 new messages