Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Are there clients that don't break when you change the API the client works with? Pretty smart clients.

Yes, you can write clients for GitHub's API that works that way, for example.

Here, I whipped you up one: https://gist.github.com/steveklabnik/5282209/e48b100d95ff77f...

This client will return you information about the first gist on the second page of the public list. It does this by fetching the list of gists from the root, then using the pagination to walk forward. GitHub can change all of this, and it'll still work.

  $ ruby fetch_gists.rb
  DATA:
  ID:	5282131
  URL:	https://api.github.com/gists/5282131
  USER:	sparksp
Bonus: here's a slightly refactored version. The logic is more clear when you move things into helpers. https://gist.github.com/steveklabnik/5282209/52ed62366586838...


If I may, the goal seems a bit incorrectly specified for hypermedia. For instance, if github decided to change the number of results they return per page, then your script would not break, but it would have a different meaning.

I would suggest a better goal to be "get the 11th public gist". Although that still isn't perfect since it doesn't mention how the collection would be sorted (I presume by date).


Absolutely, this goal is bad. I was just trying to show off the mechanics, and that clients don't have to be complex.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: