Evolution of API With Blogging

75
ution of API With Blogg YAPC::Asia Tokyo 2011 Takatsugu Shigeta YAPC::Asia Tokyo 2011 by Japan Perl Association is licensed under a Creative Commons Display - Non-Commercia

description

http://yapcasia.org/2011/talk/48This talk is created by OpenOffice on Ubuntu. Including fonts are a little bit funny. Thank you for your interestings.

Transcript of Evolution of API With Blogging

Page 1: Evolution of API With Blogging

Evolution of API With Blogging

YAPC::Asia Tokyo 2011Takatsugu Shigeta

YAPC::Asia Tokyo 2011 by Japan Perl Association is licensed under a Creative Commons Display - Non-Commercial 2.1 Japan License.

Page 2: Evolution of API With Blogging

Before starting my talk...

I deeply apologize for not realizing to write some code.

I mentioned below in a description of my talk.

“I'll show you implementations of starman, Twiggy and TheSchwartz”

But that didn't match my thoughts.I don't show you that in my talk.

Page 3: Evolution of API With Blogging
Page 4: Evolution of API With Blogging

Yeah...

That's NOT stateless.I think that API should be stateless as REST.

That pattern is asynchronized.I couldn't use that pattern in API.

Page 5: Evolution of API With Blogging

Please don't throw a chairlike Steve Ballmer or kazeburo!

Page 6: Evolution of API With Blogging

Evolution of API With Blogging

YAPC::Asia Tokyo 2011Takatsugu Shigeta

YAPC::Asia Tokyo 2011 by Japan Perl Association is licensed under a Creative Commons Display - Non-Commercial 2.1 Japan License.

Page 7: Evolution of API With Blogging

Takatsugu Shigeta

comewalk

Some icons from http://icondock.com/

google-api-perl-client

A moderator of gearman/MogileFS/Perlbal mailing lists

http://blog.comewalk.com

Page 8: Evolution of API With Blogging

Perl::Evolution

Page 9: Evolution of API With Blogging

Movable Type 10th Anniversary!

Page 10: Evolution of API With Blogging

Let's talk about blogging API!

Page 11: Evolution of API With Blogging

Contents1 1983–19932 1994–20013 2001–2004

4 2004–present5 References

http://en.wikipedia.org/wiki/History_of_blogging

History Of Blogging

Page 12: Evolution of API With Blogging

1994-2001

The term "weblog" was coined by Jorn Barger on 17 Dec 1997.

The short form, "blog," was coined by Peter Merholz in April or May 1999.

LiveJournal was launched in Mar 1999.

Blogger was launched in Aug 1999.

http://en.wikipedia.org/wiki/History_of_blogging

Page 13: Evolution of API With Blogging

2001-2004

Movable Type was released in Oct 2001.

By 2001, blogging community increased rapidly.

http://en.wikipedia.org/wiki/History_of_blogging

Page 14: Evolution of API With Blogging

2004

Page 15: Evolution of API With Blogging

2011

YAPC::Asia Tokyo 2011

Evolution of API With Blogging

Page 16: Evolution of API With Blogging

“Learn from yesterday, live for today, hope for tomorrow. The important thing is not

to stop questioning.”

- Albert Einstein

温故知新

- 孔子

Why?

Page 17: Evolution of API With Blogging

Here we go!

Page 18: Evolution of API With Blogging
Page 19: Evolution of API With Blogging
Page 20: Evolution of API With Blogging
Page 21: Evolution of API With Blogging

Sample

use Data::Dumper;use Net::Trackback::Client;use Net::Trackback::Ping;

my $ping = Net::Trackback::Ping->new({ ping_url => 'http://example.com/trackback/1234/5678', url => 'http://example.com/blog/2011/10/post-1.html', title => 'Yet Another Trackback Test', description => 'This trackback which is generated by Net::Trackback.',});my $client = Net::Trackback::Client->new;my $msg = $client->send_ping($ping);say Dumper($msg);

Page 22: Evolution of API With Blogging
Page 23: Evolution of API With Blogging

Sample

use URI;use XML::Feed;

my $uri = URI->new('http://example.com/rss.xml');my $parser = XML::Feed->parse($uri);say $parser->as_xml;

Page 24: Evolution of API With Blogging
Page 25: Evolution of API With Blogging
Page 26: Evolution of API With Blogging

Sample

use Data::Dumper;use XML::Feed;

my $uri = 'http://example.com';my @urls = XML::Feed->find_feeds($uri);say Dumper(@urls);

Page 27: Evolution of API With Blogging
Page 28: Evolution of API With Blogging

use URI;use XML::FOAF;

my $uri = URI->new('http://example.com');my $foaf = XML::FOAF->new($uri);say $foaf->person->nick;

Sample

Page 29: Evolution of API With Blogging

Auto-Discovery<link rel="alternate" type="application/atom+xml"

title="Atom" href="http://example.com/atom.xml" /><link rel="alternate" type="application/rss+xml"

title="RSS 1.0" href="http://example.com/index.rdf" />

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://example.com/rss.xml" />

<link rel="openid.server" href="http://example.com/openid/server" />

<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://example.com/rsd/123" />

<link rel="meta" type="application/rdf+xml" title="FOAF" href="http://example.com/foaf.rdf" />

Page 30: Evolution of API With Blogging

Sample

use Data::Dumper;use WWW::Blog::Metadata;

# seealso: perldoc WWW::Blog::Metadatause WWW::Blog::Metadata::RSD;

My $uri = 'http://example.com';my $meta = WWW::Blog::Metadata->extract_from_uri($uri);say Dumper($meta->feeds);say Dumper($meta->rsd_uri);

Page 31: Evolution of API With Blogging

Mobile Link Discovery

<link rel="alternate" media="handheld" type="application/xhtml+xml"

href="http://example.com/mobile" />

WWW::Blog::Metadata::MobileLinkDiscovery

http://www.sixapart.jp/docs/tech/mobile_link_discovery_en.html

Page 32: Evolution of API With Blogging
Page 33: Evolution of API With Blogging

XMLRPC

use Data::Dumper;use RPC::XML::Client;

my $client = RPC::XML::Client->new('http://www.typepad.jp/t/api');

my $request = RPC::XML::request->new( 'mt.supportedMethods',);my $response = $client->send_request($request);say Dumper($response);

Page 34: Evolution of API With Blogging

XMLRPC

use Data::Dumper;use XMLRPC::Lite;

my @result = XMLRPC::Lite ->proxy('http://www.typepad.com/t/api') ->call('mt.supportedMethods') ->result;say Dumper(@result);

Page 35: Evolution of API With Blogging

AtomPub

use XML::Atom::Client;use XML::Atom::Entry;

my $entry = XML::Atom::Entry->new;

$entry->title('This entry is posted by Atom.');$entry->content('Atom Atom Atom Atom');

my $api = XML::Atom::Client->new;$api->username('YourUserName');$api->password('YourPassword');

my $PostURI = "http://example.com/atom/weblog/blog_id=YourBlogID";

my $EditURI = $api->createEntry($PostURI, $entry);

Page 36: Evolution of API With Blogging

WSSE

my $nonce = $client->make_nonce;my $nonce_enc = encode_base64($nonce, '');my $now = DateTime->now->iso8601 . 'Z';my $digest = encode_base64(sha1($nonce . $now .

($client->password || '')), '');$req->header('X-WSSE', sprintf qq(UsernameToken Username="%s",

PasswordDigest="%s", Nonce="%s", Created="%s"), $client->username || '', $digest, $nonce_enc,

$now);$req->header('Authorization', 'WSSE

profile="UsernameToken"');

Code From XML::Atom::Client

Page 37: Evolution of API With Blogging

RSD<?xml version="1.0"?><rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> <service> <engineName>TypePad</engineName> <engineLink>http://www.typepad.com/</engineLink><homePageLink>http://blog.comewalk.com/</homePageLink> <apis> <api name="Atom" preferred="false"

apiLink="http://www.typepad.com/services/atom/svc=blogs/blog_id=123" />

<api name="MetaWeblog" preferred="true" apiLink="http://www.typepad.com/services/xmlrpc" blogID="123" />

<api name="Blogger" preferred="false" apiLink="http://www.typepad.com/services/xmlrpc" blogID="123" />

<api name="MovableType" preferred="false" apiLink="http://www.typepad.com/services/xmlrpc" blogID="123" />

</apis> </service></rsd>

Page 38: Evolution of API With Blogging
Page 39: Evolution of API With Blogging

weblogUpdates Pingmy $url = 'http://rpc.weblogs.com/RPC2';my $req = HTTP::Request->new('POST', $url);$req->header('Content-Type' => 'text/xml');my $text = <<XML;<?xml version="1.0"?><methodCall> <methodName>weblogUpdates.ping</methodName> <params> <param><value>Foo::Bar</value></param> <param><value>http://example.com</value></param> </params></methodCall>XML$req->content($text);my $ua = LWP::UserAgent->new;my $res = $ua->request($req);

Page 40: Evolution of API With Blogging

OpenSearch

<link rel="search" type="application/opensearchdescription+xml" href="http://example.com/opensearch/search.xml" title="" />

seealso WWW::OpenSearch

Page 41: Evolution of API With Blogging

OpenID

seealso Net::OpenID::Consumer

Page 42: Evolution of API With Blogging
Page 43: Evolution of API With Blogging

PubSubHubbub

http://code.google.com/p/pubsubhubbub/

Page 44: Evolution of API With Blogging

PubSubHubbub

Implementations

Publisherhttp://pubsubhubbub.googlecode.com/svn/trunk/

Hubhttp://pubsubhubbub.appspot.com/

Subscriberttp://d.hatena.ne.jp/tokuhirom/20100307/push

Page 45: Evolution of API With Blogging
Page 46: Evolution of API With Blogging
Page 47: Evolution of API With Blogging

Trackback

XMLRPCAtomPub

Comment

RSD

weblogUpdates Ping

Update Stream

RSS Atom

Activity Streams

OpenSearch

JSON

PubSubHubbub

OpenID

OAuthWSSE

FOAF

oEmbed

OPML

Auto-DiscoveryMobile Link Discoverymicroformats

Page 48: Evolution of API With Blogging

Full view

Page 49: Evolution of API With Blogging

Anyway,

Are you enjoying YAPC::Asia?

Page 50: Evolution of API With Blogging
Page 51: Evolution of API With Blogging
Page 52: Evolution of API With Blogging

This is very precious to me in YAPC::Asia Tokyo 2011!

Did you have anything like this?

You should talk with ROCK STARS!

Page 53: Evolution of API With Blogging

Okay,

back to my talk

Page 54: Evolution of API With Blogging

Further Progress of API

Page 55: Evolution of API With Blogging

JSON

XML is still used as structured data/representation like HTML

But response of API is moving to JSON.

Page 56: Evolution of API With Blogging

With Document

Your service should provide API explorerwith API documentation

http://explorer.metacpan.org/

http://code.google.com/apis/explorer/

https://developer.foursquare.com/docs/explore.html

Page 57: Evolution of API With Blogging

PATCH Method

PATCH method allows us to apply partial modifications to a resource.

RFC5789 PATCH Method for HTTPhttp://www.ietf.org/rfc/rfc5789.txt

e.g.)http://developer.github.com/v3/#http-verbs

Page 58: Evolution of API With Blogging

PATCH MethodPATCH /gists/:id

{ "description": "the description for this gist", "files": { "file1.txt": { "content": "updated file contents" }, "old_name.txt": { "filename": "new_name.txt", "content": "modified contents" }, "new_file.txt": { "content": "a new file" }, "delete_this_file.txt": null }}

http://developer.github.com/v3/gists/

Page 59: Evolution of API With Blogging

And Also ...

REST (HTTP verbs, Resource, URI)Authentication (OAuth2)

Rate Limiting

Page 60: Evolution of API With Blogging

And more...

Performance Tips

Using gzip

Working with partial response

http://code.google.com/apis/discovery/v1/performance.html

Page 61: Evolution of API With Blogging

Working With Partial Resourcehttps://www.googleapis.com/demo/v1?key=YOUR-API-KEY

200 OK

{ "kind": "demo", ... "items": [ { "title": "First title", "comment": "First comment.", "characteristics": { "length": "short", "accuracy": "high", "followers": ["Jo", "Will"], }, "status": "active", ... }, { "title": "Second title", "comment": "Second comment.", "characteristics": { "length": "long", "accuracy": "medium" "followers": [ ], }, "status": "pending", ... }, ... ]}}

https://www.googleapis.com/demo/v1?key=YOUR-API-KEY&fields=kind,items(title,characteristics/length)

200 OK

{ "kind": "demo", "items": [ { "title": "First title", "characteristics": { "length": "short" } }, { "title": "Second title", "characteristics": { "length": "long" } }, ... ]}

Page 62: Evolution of API With Blogging

Think New Specifications

Page 63: Evolution of API With Blogging

Think Data Portability

These formats couldn't resolveto clone our data completely

Movable Type Import/Export Format

WordPress eXtended RSS Format

Atom (Blogger)

Import/Export

Page 64: Evolution of API With Blogging

Import/Export

Next Future?

Camlistore is a way to store, sync, share, model and back up content

http://camlistore.org/

Page 65: Evolution of API With Blogging

Semantic Web

Which tools?

Page 66: Evolution of API With Blogging

Blogging World Is Still Fun,Let's Hack Together!

Page 67: Evolution of API With Blogging

Kudos To CPAN Authors!

Data::Dumper Net::Trackback HTTP::Request Plagger LWP::UserAgent WWW::Search XML::Feed WWW::Blog::Metadata (Web::Scraper) XML::Atom

RPC::XML XMLRPC::Lite

Especially,miyagawa++

Perl Modules I Mentioned

Page 68: Evolution of API With Blogging

Finally,

I would like to introduce a module for you

Page 69: Evolution of API With Blogging

google-api-perl-client

Google APIs Client Library for Perl

http://code.google.com/p/google-api-perl-client/

https://github.com/comewalk/google-api-perl-client/

Page 70: Evolution of API With Blogging

use URI;use Google::API::Client;

my $client = Google::API::Client->new;My $service = $client->build('urlshortener', 'v1');

# Create a shortened URL by inserting the URL into the url collection.my $body = { 'longUrl' => 'http://code.google.com/apis/urlshortener/',};

my $res = $service->url->insert(body => $body)->execute;say 'short url is' . $res->{'id'};

Page 71: Evolution of API With Blogging

I WAS VERY VERY EXCITED!

Joe Gregorio mentioned the module in his Google+ stream.

Brad Fitzpatrick directly emailed me that he can help me the module by code review or something like that.

Page 72: Evolution of API With Blogging

I'll keep updating the module.

And,if you are a programmer,

also you can write some code.Right?

Page 73: Evolution of API With Blogging

That's all,Thank you!

Page 74: Evolution of API With Blogging

I'm using USB-booted Ubuntu

VOTE ME!

Page 75: Evolution of API With Blogging

THANK YOU!