Services Blog Français

Django & ajax & HATEOAS: how to reverse urls in javascript (not)

| by jpic | http hateoas api

This is the second article about reversing urls in javascript. The previous article actually presented a bad idea.

Github API v3

Github’s API is undubitably quite suprising for a web developer that isn’t aware of the HATEOAS concept, here’s the kind of things you can see for example:

    "updated_at": "2012-11-27T14:42:24Z",
    "svn_url": "",
    "language": "Python",
    "milestones_url": "{/number}",
    "downloads_url": "",
    "subscription_url": "",
    "teams_url": "",
    "full_name": "yourlabs/django-cities-light",
    "git_url": "git://",
    "git_tags_url": "{/sha}",
    "owner": {
      "login": "yourlabs",
      "organizations_url": "",
      "followers_url": "",
      "starred_url": "{/owner}{/repo}",
      "following_url": "",
      "avatar_url": "",
      "repos_url": "",
      "subscriptions_url": "",
      "url": "",
      "events_url": "{/privacy}",
      "gravatar_id": "c0efe8e5c15bd268224fbc40a574329d",
      "received_events_url": "",
      "id": 1040547,
      "gists_url": "{/gist_id}"

Wow, so many URLs… At first, this may look original, if not excentric. Why aren’t they just documented ?


Lee Wayne’s presentation of HATEOAS is amazingly easy to understand. So I’ll just resume it.

Clients should not reverse urls

From what I understand, there should be a gate url, that returns all urls and some data. Working with a non HATEOAS API looks like this:

  • search documentation for the url you need,
  • try to figure out how to “cook” urls to get what you need.

With the GitHub API it looks like this:

  • find the gate url,
  • use the returned data to generate URLs, don’t hardcode any url.


A thousand thanks to django-developers mailing list and particularely to Javier Guerra Giraldez for pointing me in the right direction.

They trust us