Providing a Public API

Marc Tobias Metten

Lokku Ltd.

HTML output

property for sale in Oxford
property for sale in Oxford

JSON output

http://api.nestoria.es/api?action=search_listings&place_name=palma+de+mallorca&listing_type=rent
"response" : {
    "created_http" : "Mon, 07 May 2007 12:00:44 GMT",
    "created_unix" : 1178539244,
    "link_to_url" : "http://www.nestoria.es/palma-de-mallorca/casa/alquiler/num_res-20",
    "listings" : [
      {
        "bathroom_number" : 2,
        "bedroom_number" : 2,
        "datasource_name" : "Atrea",
        "keywords" : "Furnished, Attic",
        "latitude" : 39.5366,
        "lister_name" : "Alfa",
        "lister_url" : "http://rd.nestoria.es/rd?l=api-sr-title-1&sc=1-13946&url=1-U2FsdGVk....",
        "listing_type" : "let",
        "longitude" : 2.71594,
        "price" : 750,
        "price_currency" : "EUR",
        "price_formatted" : "750 EUR",
        "price_type" : "monthly",
        "property_type" : "flat",
        "summary" : "Bonito atico en las maravillas nuevo a estrenar, vistas al mar y...",
        "thumb_height" : 60,
        "thumb_url" : "http://limg.nestoria.es/c/3/c32295a2a0251437bd9981a0633158aa.jpg",
        "thumb_width" : 60,
        "title" : "Piso de 2 habitaciones en alquiler"
      },
    ]
    "attribution" : {
          "img_url" : "http://static.nestoria.es/i/realestate/es/es/pb2.png",  
          "img_height" : 20,
          "img_width" : 199,
          "link_to_img" : "http://www.nestoria.es",
    }
  
ukpropertyvision.com

Different kinds

ProgrammableWeb.com lists 560 APIs

Cool APIs

REST Definition

"HTTP is stateless. Each message contains all the information necessary to understand the request when combined with state at the resource. As a result, neither the client nor the server needs to remember any communication state between messages. Any state retained by the server must be modeled as a resource."
source: wikipedia

REST Overview


RESTful web services

Perl - Resource

    use URI;

    my $url = URI->new('http://api.nestoria.co.uk/api');
    $url->query_form(
         action        => 'search_listings',
         encoding      => 'json',
         pretty        =>  1,

         listing_type  => 'buy',
         property_type => 'flat',
         place_name    => 'Greenwich',
         bedroom_min   => 2,
         bedroom_max   => 2,
    );
    
    ##
    ## http://api.nestoria.co.uk/api?action=search_listings&encoding=json&pretty=1...
    ##

Perl - Request

    use LWP::Simple;
    
    my $response_json = get($url->as_string());

Perl - Response

    use JSON::XS;
    
    my $response      = from_json($response_json);

    printf("found %d results near %s\n\n",
         $response->{response}{total_results},
         $response->{response}{locations}->[0]->{title}
    );
    my $ra_listings = $response->{response}{listings};

    foreach ( @$ra_listings ){
         printf("%-50s | %12s | %.5f, %.5f\n",
             $_->{title},
             $_->{price_formatted},
             $_->{longitude},
             $_->{latitude},
         );
    }

Perl - Response formatted

found 324 results near Greenwich

2 bedroom flat for sale                            |  269,995 GBP |  -0.02161, 51.47150
Gainsborough House, Canary Wharf, E14              |  385,000 GBP |  -0.02188, 51.49850
3 Millennium Drive                                 |  399,950 GBP |  -0.00632, 51.49200
Discovery Dock East, E14                           |  800,000 GBP |  -0.02336, 51.49770
March Wall, Isle Of Dogs,, E14                     |  349,995 GBP |  -0.02468, 51.50040
Dunstable Ct, 12 St. Johns Pk, Blackheath          |  275,000 GBP |   0.01452, 51.47450
Flat for sale, E14                                 |  435,000 GBP |  -0.02651, 51.49140
2 bedroom flat to buy                              |  320,000 GBP |  -0.02301, 51.47250
Wheel House, Burrells Wharf, Isle Of Dogs, E14     |  442,000 GBP |  -0.02095, 51.48680
Pan Peninsula, E14                                 |  635,000 GBP |  -0.01320, 51.49930
Fergusons Wharf, 214 Westferry Road                |  320,000 GBP |  -0.01803, 51.48770
Westferry Point/ 156 Westferry Road, E14           |  335,000 GBP |  -0.01803, 51.48770
Nova Building, Odyssey, E14                        |  465,000 GBP |  -0.02791, 51.49230
River View Court, Old Bell Gate, E14               |  375,000 GBP |  -0.02783, 51.49410
Becquerel Court, W. Parkside, SE10                 |  399,995 GBP |   0.00687, 51.49710
Flat for sale, New Cross                           |  175,000 GBP |  -0.03709, 51.47990
2 bedroom flat for sale                            |  320,000 GBP |  -0.02371, 51.48960

The Resource

The Request

The Response

HTTP content-types

Response (error) codes

HTTP response codes

errors - examples

adding layers

lessons learned

what we do


houseprice widget

why we do it


OpenStreeMap on Garmin

lessons learned

lessons learned

language wrappers

problems

API versioning

problems

user requests and feedback

users want everything


download wikipedia

Terms of Service

"You may not frame or link to the web site or any part of it without our express permission."
not nestoria

robots.txt

robots.txt

Questions?

mtm -at- lokku.com
www.nestoria.co.uk/help/api

backup - problems with return values