SlideShare uma empresa Scribd logo
1 de 15
Great APIs

 @ChrisSinjo
IPRUG – 05/03/2013
A piece of a larger talk
Caution: Opinions ahead
What is “great”?

Spend most
 time here      Nice high level APIs


Go here when
  I’m doing     Powerful, underlying
 something
 awesome              toolset
Git calls this “porcelain” and
          “plumbing”
Example: get something over
          HTTP
In my mind (psuedocode)
# Gives me the response contents as a string
print 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
 people with beards ahead
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();
    }
}
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 thing

At least not entirely (syntactic flexibility aside)
Community focus?

      Broadly:
   Java: ↑ plumbing
   Ruby: ↑ porcelain
There is more to great APIs
         than this
Questions?

Mais conteúdo relacionado

Mais procurados

Mock cli with Python unittest
Mock cli with Python unittestMock cli with Python unittest
Mock cli with Python unittestSong Jin
 
Doppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language BarrierDoppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language BarrierEmery Berger
 
Asynchronous Python and You
Asynchronous Python and YouAsynchronous Python and You
Asynchronous Python and YouAddShoppers
 
Groovy
GroovyGroovy
Groovyatonse
 
Lowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost PortablyLowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost PortablyESUG
 
PhpSpec: practical introduction
PhpSpec: practical introductionPhpSpec: practical introduction
PhpSpec: practical introductionDave Hulbert
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parserfukamachi
 
Some Rough Fibrous Material
Some Rough Fibrous MaterialSome Rough Fibrous Material
Some Rough Fibrous MaterialMurray Steele
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lispfukamachi
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Pythongturnquist
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPCAnthony Ferrara
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and coPierre Joye
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from DataMosky Liu
 

Mais procurados (20)

Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
 
Mock cli with Python unittest
Mock cli with Python unittestMock cli with Python unittest
Mock cli with Python unittest
 
Doppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language BarrierDoppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language Barrier
 
Asynchronous Python and You
Asynchronous Python and YouAsynchronous Python and You
Asynchronous Python and You
 
Groovy
GroovyGroovy
Groovy
 
Lowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost PortablyLowcode: Redoing NativeBoost Portably
Lowcode: Redoing NativeBoost Portably
 
Getting testy with Perl
Getting testy with PerlGetting testy with Perl
Getting testy with Perl
 
Ruby Blocks
Ruby BlocksRuby Blocks
Ruby Blocks
 
PhpSpec: practical introduction
PhpSpec: practical introductionPhpSpec: practical introduction
PhpSpec: practical introduction
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parser
 
Some Rough Fibrous Material
Some Rough Fibrous MaterialSome Rough Fibrous Material
Some Rough Fibrous Material
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lisp
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Gohan
GohanGohan
Gohan
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 

Destaque

Improving your shell usage - 2009
Improving your shell usage - 2009Improving your shell usage - 2009
Improving your shell usage - 2009Chris Sinjakli
 
Improving your shell usage - 2010
Improving your shell usage - 2010Improving your shell usage - 2010
Improving your shell usage - 2010Chris Sinjakli
 
Mutation Testing - Ruby Edition
Mutation Testing - Ruby EditionMutation Testing - Ruby Edition
Mutation Testing - Ruby EditionChris Sinjakli
 
Byteman - Carving up your Java code
Byteman - Carving up your Java codeByteman - Carving up your Java code
Byteman - Carving up your Java codeChris Sinjakli
 
Mutation testing
Mutation testingMutation testing
Mutation testingTao He
 
Mutation Testing
Mutation TestingMutation Testing
Mutation TestingESUG
 

Destaque (7)

Improving your shell usage - 2009
Improving your shell usage - 2009Improving your shell usage - 2009
Improving your shell usage - 2009
 
Improving your shell usage - 2010
Improving your shell usage - 2010Improving your shell usage - 2010
Improving your shell usage - 2010
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 
Mutation Testing - Ruby Edition
Mutation Testing - Ruby EditionMutation Testing - Ruby Edition
Mutation Testing - Ruby Edition
 
Byteman - Carving up your Java code
Byteman - Carving up your Java codeByteman - Carving up your Java code
Byteman - Carving up your Java code
 
Mutation testing
Mutation testingMutation testing
Mutation testing
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 

Semelhante a Great APIs

Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Baruch Sadogursky
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHPKing Foo
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
Client server part 12
Client server part 12Client server part 12
Client server part 12fadlihulopi
 
Scalalable Language for a Scalable Web
Scalalable Language for a Scalable WebScalalable Language for a Scalable Web
Scalalable Language for a Scalable WebTimothy Perrett
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)guregu
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA PresentationRob Tweed
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTPMykhailo Kolesnyk
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Modulearjun singh
 
Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)James Titcumb
 
Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and PythonAndreas Schreiber
 

Semelhante a Great APIs (20)

Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Client server part 12
Client server part 12Client server part 12
Client server part 12
 
Scalalable Language for a Scalable Web
Scalalable Language for a Scalable WebScalalable Language for a Scalable Web
Scalalable Language for a Scalable Web
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
 
Php
PhpPhp
Php
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Module
 
Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)
 
Apache Beam de A à Z
 Apache Beam de A à Z Apache Beam de A à Z
Apache Beam de A à Z
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
ReactPHP
ReactPHPReactPHP
ReactPHP
 
Tatsumaki
TatsumakiTatsumaki
Tatsumaki
 
Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and Python
 

Great APIs

  • 2. A piece of a larger talk
  • 4. What is “great”? Spend most time here Nice high level APIs Go here when I’m doing Powerful, underlying something awesome toolset
  • 5. Git calls this “porcelain” and “plumbing”
  • 7. In my mind (psuedocode) # Gives me the response contents as a string print HttpLibrary.get('http://ifconfig.me/ip').body
  • 8. In Ruby (with HTTParty) puts HTTParty.get('http://ifconfig.me/ip').body
  • 9. Caution: Serious, heavy- duty, enterprise language for people with beards ahead
  • 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(); } }
  • 11. In Java (with fluent-hc wrapper) String ip = Request.Get("http://ifconfig.me/ip") .execute().returnContent().asString(); System.out.println(ip);
  • 12. This isn’t a language thing At least not entirely (syntactic flexibility aside)
  • 13. Community focus? Broadly: Java: ↑ plumbing Ruby: ↑ porcelain
  • 14. There is more to great APIs than this

Notas do Editor

  1. Which I haven’t written yet, but keep toying with
  2. Talk is opinionatedBased on my experience developing in both Ruby and Java over the last yearI’m not saying any of the APIs in this talk are bad, just that some of them lack fluidityThe one I use as an example of “bad” is actually a really robust implementation on the whole
  3. How I like APIs to be splitIf you’ve used git a lot, you’ve probably heard the terms “porcelain” (high level bits) and “plumbing” (low level bits)
  4. Happened to be doing this last week
  5. I was doing this for an Android app, so writing Java
  6. A nice wrapper around the library from the last page