LA RubyConf 2009 Waves And Resource-Oriented Architecture

30
And Why It Matters And How Waves Make It Easier Resource-Oriented Architecture

Transcript of LA RubyConf 2009 Waves And Resource-Oriented Architecture

And Why It MattersAnd How Waves Make It Easier

Resource-Oriented Architecture

dan yoderdirector.hacking

[email protected]://twitter.com/dyoder

http://dev.zeraweb.com/

AutoCode • Functor • Filebase Waves • Pages • Hoshi • DateJS

interactiver&d

The Web works pretty well.

0

40

80

120

160

2005 2006 2007 2008

Scalability?The Web Has It.

Web Sites (M)

H T M LJ S O NC S S

M I M EX M LR S SR D F

Open? Yep. Mostly, anyway.

Existing Infrastructure?Firewalls, Edge Caches, Proxy Servers, Etc.

But why does it work?

The Web Isn’t MVCSo Why Do We Use It So Often For Web Apps?

http://www.flickr.com/photos/seokchanyun/

RSS: From Blogs To PodcastsFeed provides RDF-like metadata, media-type can vary, many different clients.http://www.flickr.com/photos/abletoven/

OAuth Smart ProxiesLike firewalls for your apps - implementors don’t need to add OAuth support directly.

ConsumerProviderProxy

get request token

get permissionResource

access token

OAuthHTTP Auth

login

grant permission

access resource

Video SearchEdge caching takes the burden of caching away from overloaded servers.http://www.flickr.com/photos/33122834@N06/

Taking a step back ...

ROA Is Just Distributed Objects.Except based on Fielding’s REST constraints.

ROA Solves An Old Problem.RPC? CORBA? DCOM? DSOM? RMI? SOA?

http://www.flickr.com/photos/secretlondon/

Learning From Past Mistakes

Be platform neutral.Don’t assume anything about the format of an object. Let the client specify it, instead.http://www.flickr.com/photos/dirigibleduck/

Be Wire Neutral, Too.Protocols evolve and change. Make it possible to link to resources using older protocols.http://www.flickr.com/photos/megans_photography/

Define Meta-Object Protocols“Uniform stateless interface” means rich interactions happen on the client.

Don’t Forget Performance.This means edge caching and pushing computation out to the client.http://www.flickr.com/photos/24293932@N00/

Allow Layered ArchitecturesProxies and gateways can decouple server implementations from network policies.http://www.flickr.com/photos/rengel134/

Waves and ROA ...

Rich DSL for HTTP requestson( :get, [ ‘location’ ], :query => { :lat => /\d{4}/, :long => /\d{4}/ }, :accept => [ :json, :xml ] )

But it’s still just Ruby ...pages $ waves console

Pages::Resources::Story.instance_methods & %w( get put post delete )

# => ["delete", "post", "put", "get"]

Resource Classes

Inheritance. I can now just inherit from a base class to provide common REST features.

Modularity. Request-handling is broken down into logically discrete chunks, just like normal classes.

Performance. I don’t have to go through each possible match - just those for the matching resource.

The One File Waves App

module HelloWorld

include Waves::Foundations::Compact module Resources class Map on( :get, [] ) { "Hello #{query.name}" } end end

end

Roadmap# TODO: this is a hack ...

A Resource DSL

class Blog include Waves::Resource::Server   resource :list, :expires => 3.days, [ ‘blogs’ ]  do    get { model.find_all }  end  resource :element, :expires => 3.days, [ ‘blog’, :name ]  do    get { model.find_by_name( captured.name ) }  end  schema :element, [ 'schema', 'blog', '2009-03' ] do    attributes :title => String, :description => String    link :entries, :list => Story  end  representations :list do   as :html, :lang => :en do | blogs |     view( :blog ).list( blogs )   end  endend

Waves::Vitals

Initial 0.7.0 release Feb 08Release 0.8.3 Available Soon!

Of course, we’re on git.http://github.com/waves/stable

Join Us On Google Groups.rubywaves

irc:freenode.net#waves

And, lest we forget, a Web site.http://rubywaves.com/

Shout Outpolymar, rue, leetspete, kaykay, automatthew, pascal, copawaves, and many others.

Thanks!