May 2008

Close, but no Cigar for oEmbed

oEmbed is a brand new specification from Cal Henderson, Mike Malone, Leah Culver and Richard Crowley with one goal: Display embedded content without having to parse the resource directly.

I like the idea. Not only because I thought of something similar a time ago, but mainly because it sucks to parse data you don’t have control over. You have to fetch lots of unneeded data and the format might change.


When I first read the specification, it seemed very clear and semantic. After reading oEmbed using HTTP headers? it just seemed to follow bad common practice of HTTP1. It was also pointed out that there exists an almost equal specification: LinkHeader.

Did you say “well formed JSON”?

In the specification they say: “JSON responses must contain well formed JSON” and gives us this example:

  foo: 'bar',
  baz: 1,

Something is wrong here. That is just a regular JavaScript object! Try to feed it to a strict JSON parser and see what error it throws. This, my friends, is well formed JSON:

  "foo": "bar",
  "baz": 1,


What’s really great is that they managed to get five big providers, which means it’s actually useful:

What’s not so great is that none of the providers follows the specification correctly:


I really like the idea; why couldn’t they just have implemented it with HTTP headers? Right now I’m getting the “using tables for layout”-feeling for every oEmbed-request I send. And they have to fix the JSON-problem and make all the providers follow the specification. Just look at what happened to IE.

If they don’t think HTTP headers are a good idea (or are too lazy to change the specification) and will just look away while using it. Because I like the idea, and in my opinion is the idea is the most important part.

Oh, and did someone mentioned Ruby?

# Define a provider:
flickr ="")
flickr << "http://**"

# Get raw data:
flickr.raw("", :format => :xml)

# Get a response (this doesn't work yet, due to invalid JSON):
res = flickr.get("")
res.type           # => "photo"
res.width          # => 240
res.height         # => 160
res.title          # => "ZB8T0193"
res.url            # => ""
res.author_name    # => "Bees"
res.author_url     # => ""
res.provider_name  # => "Flickr"
res.provider_url   # => ""

## Multiple providers:

# Registers Flickr, Viddler, Qik, Pownce and Revision3

# Use #get and #raw here too:
OEmbed::Providers.get("", :maxwidth => 500)
OEmbed::Providers.raw("", :format => :xml)

It’s evolving at Gitorious and GitHub