views:

21

answers:

1

If you were trying to design a language binding to a restful web api, how would you do it? What would you take into consideration? What resources would you consult first? Would you try to mock the web api interlace 1:1 or would you try to use your language idioms instead? How would you prevent making excessive HTTP requests? Etc

I've been tasked with creating a language binding for a web api and I have never done something like this before so I thought I'd ask SO before I started.

+1  A: 
  • Dont mock the web API interface — if you're bothering to write a native binding, then supposedly it's so developers don't need to learn the idioms and paradigms of the web API, and can instead use an API which is more similar to what they're used to. So use the idioms of the language.

  • Prevent excessive HTTP requests with caching

  • If the service returns an error status code (400-599) then translate that into a native error state -- exceptions, error codes, whatever.

  • make sure you account for http requests timing out or just plain old connection failures, again by throwing an exception or returning an error

  • If a service responds with a 3xx redirection status, automatically follow the redirection. Most native programmatic paradigms don't really support the concept of redirection, so just make it work.

  • Finally, the trickiest part is the paradigm translation, from RESTful to procedural. This is different for every case. Basically, you'll want a class (or object) per resource. Each class would support delete() and save(), and have getters and setters for specific aspects of the resource. You'll also need a way to check the state -- dirty, saved, etc.

(Sorry if the formatting's off here, I'm writing this on my iPad and for some reason the site doesn't show the editing toolbar or the preview.)

Avi Flax