Simon Willison’s Weblog

Subscribe

What is the best way to maintain a API wrapper class across multiple languages?

25th October 2010

My answer to What is the best way to maintain a API wrapper class across multiple languages? on Quora

1. Use JSON for your API. That takes away a lot of the necessity for an API wrapper, since it means you’re automatically returning native data types (hashes, lists, strings etc) for most programming languages.

2. Build a RESTful API which is self describing—for example, one that returns URLs to other items represented by the API. That way you can write client libraries that work against the conventions used by the API, rather than hard-coding knowledge of the API in to the library.

3. If you can’t get #2 to work (which can be quite tricky), make your client-libraries data driven—ship them with a JSON file describing the API endpoints, then you can update all of the libraries just by updating that JSON file. You could even have the client libraries pull and cache the JSON API description over HTTP so you don’t have to ship a copy with the libraries.

This is What is the best way to maintain a API wrapper class across multiple languages? by Simon Willison, posted on 25th October 2010.

Next: What are the best APIs for creating location-based Wikipedia mashups?

Previous: What does an ideal Django workflow setup look like?