Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Great APIs

Great APIs

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.

Chris Sinjakli

March 05, 2013
Tweet

More Decks by Chris Sinjakli

Other Decks in Programming

Transcript

  1. Great APIs
    @ChrisSinjo
    IPRUG – 05/03/2013

    View Slide

  2. A piece of a larger talk

    View Slide

  3. Caution: Opinions ahead

    View Slide

  4. What is “great”?
    Nice high level APIs
    Powerful, underlying
    toolset
    Spend most
    time here
    Go here when
    I’m doing
    something
    awesome

    View Slide

  5. Git calls this “porcelain” and
    “plumbing”

    View Slide

  6. Example: get something over
    HTTP

    View Slide

  7. In my mind (psuedocode)
    # Gives me the response contents as a string
    print HttpLibrary.get('http://ifconfig.me/ip').body

    View Slide

  8. In Ruby (with HTTParty)
    puts HTTParty.get('http://ifconfig.me/ip').body

    View Slide

  9. Caution: Serious, heavy-duty,
    enterprise language for people
    with beards ahead

    View Slide

  10. In Java (with commonly
    recommended 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();
    }
    }

    View Slide

  11. In Java (with fluent-hc wrapper)
    String ip = Request.Get("http://ifconfig.me/ip")
    .execute().returnContent().asString();
    System.out.println(ip);

    View Slide

  12. This isn’t a language thing
    At least not entirely (syntactic flexibility aside)

    View Slide

  13. Community focus?
    Broadly:
    Java: ↑ plumbing
    Ruby: ↑ porcelain

    View Slide

  14. There is more to great APIs
    than this

    View Slide

  15. Questions?

    View Slide