My lightning talk on one aspect of what I think makes a great API. Given at IPRUG lightning talks, and later at a work event.
Great APIs@ChrisSinjoIPRUG – 05/03/2013
View Slide
A piece of a larger talk
Caution: Opinions ahead
What is “great”?Nice high level APIsPowerful, underlyingtoolsetSpend mosttime hereGo here whenI’m doingsomethingawesome
Git calls this “porcelain” and“plumbing”
Example: get something overHTTP
In my mind (psuedocode)# Gives me the response contents as a stringprint HttpLibrary.get('http://ifconfig.me/ip').body
In Ruby (with HTTParty)puts HTTParty.get('http://ifconfig.me/ip').body
Caution: Serious, heavy-duty,enterprise language for peoplewith beards ahead
In Java (with commonlyrecommended HttpClient)HttpClient httpclient = new DefaultHttpClient();HttpGet httpget = new HttpGet("http://ifconfig.me/ip");HttpResponse response = httpclient.execute(httpget);HttpEntity entity = response.getEntity();if (entity != null) {InputStream myIpStream = entity.getContent();try {BufferedReader reader = new BufferedReader(new InputStreamReader(myIpStream, Charset.forName("UTF-8")));String nextLine;while ((nextLine = reader.readLine()) != null) {System.out.println(nextLine);}} finally {myIpStream.close();}}
In Java (with fluent-hc wrapper)String ip = Request.Get("http://ifconfig.me/ip").execute().returnContent().asString();System.out.println(ip);
This isn’t a language thingAt least not entirely (syntactic flexibility aside)
Community focus?Broadly:Java: ↑ plumbingRuby: ↑ porcelain
There is more to great APIsthan this
Questions?