Slideshare.net (beta)

 
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons



All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 0 (more)

Halcyon Atlanta RUG Presentation

From maraby, 3 months ago

Presenting the Halcyon JSON web app framework to Atlanta Ruby User more

296 views  |  0 comments  |  0 favorites  |  2 downloads
 

Groups/Events

Not added to any group/event

 
 

Privacy InfoNew!

This slideshow is Public

 
Embed in your blog
Embed (wordpress.com)
custom

Slideshow Statistics
Total Views: 296
on Slideshare: 296
from embeds: 0* * Views from embeds since 21 Aug, 07

Slideshow transcript

Slide 1: Halcyon

Slide 2: I WORK occasionally

Slide 3: HALCYON web app framework

Slide 4: HALCYON JSON light weight data transport layer HTTP cross-platform communications layer Rack app/server abstraction layer Merb core extensions & router

Slide 5: similar to XML easy to read & write (unlike XML) serializable JSON cross platform

Slide 6: cross platform request/response model REST HTTP uniform resource identifiers

Slide 7: small core simple rules powerful abstractions Rack Jim Weirich

Slide 8: modular active community, ever increasing code quality well documented Merb easy

Slide 9: GETTING STARTED installation, initialization, running, and customization

Slide 10: $ sudo gem install --source= http://halcyon.rubyforge.org/latest/ or $ git clone git://github. com/mtodd/halcyon.git $ cd halcyon; rake install $ sudo gem install json Installation

Slide 11: $ cd ~/Projects/ Initialization $ halcyon init app_name

Slide 12: $ cd ~/Projects/app_name/ $ halcyon run -p 4647 or $ thin start -p 4647 Running as of Thin 0.8.0

Slide 13: Customization CONTROLLERS found in app/ inherits from Application ROUTES found in config/initializer.rb will be config/initializers/routes.rb CLIENTS found in lib/client.rb simplifies calling actions' URLs

Slide 14: Controllers app/foo.rb class Foo < Application def random ok rand(10) end def greet ok "Hello #{params[:name]}!" end end

Slide 15: Routes config/initialize.rb class Halcyon::Application route do |r| r.match('/hello/:name'). to(:controller => 'foo') r.match('/rand'). to(:controller => 'foo', :action => 'random') # defines /:controller/:action/:id and family # r.default_routes end end

Slide 16: Clients lib/client.rb class AppAgent < Halcyon::Client def greet(name) get("/hello/#{name}")[:body] end def random get('/rand')[:body] end end

Slide 17: Run & Test RUN $ halcyon start -p 4647 TEST $ irb -rubygems -r lib/client >> client = AppAgent.new( "http://localhost:4647/") => #<AppAgent> >> client.rand => 4 >> client.greet("Matt") => "Hello Matt!" >> client.get("/foo") => {:status=>404,:body=>"Not Found"}

Slide 18: Run & Test Interactively OR $ halcyon irb >> get "/rand" => {:status=>200,:body=>7} >> get "/hello/Matt" => {:status=>200,:body=>"Hello Matt!"} >> client.get("/foo") => {:status=>404,:body=>"Not Found"}

Slide 19: ADVANCED TOPICS databases, Rack magic

Slide 20: DATABASES – ORM agnostic ActiveRecord in config/initialize.rb class Halcyon::Application DataMapper startup do |config| # connect to DB of your choice here. # define in $global_variable (bleh) # or Constant. Sequel end end ET AL

Slide 21: RACK MAGIC API Handler routes matching pattern deferred finds the first app that can handle request Cascade change the content type for all responses Content-Type reload classes when modified Reloader track referrers Referrer

Slide 22: RACK MAGIC – API Handler class ApiHandler def initialize(app, api); @app, @api = app, api; end def call(env) req = Merb::Request.new(env) if request.path =~ %r{^/api/(.*)} @api.call(env) else @app.call(env) end end end use ApiHandler, Halcyon::Runner.new run Merb::Rack::Application.new

Slide 23: RACK MAGIC – Cascade Similar to previous example, only using Rack::Cascade. run Rack::Cascade, [ Halcyon::Runner.new, Merb::Rack::Application.new ] Just define routes so that the Halcyon app won't prevent the Merb app from ever running. (Require /api/ in front of all routes for Halcyon, for instance.)

Slide 24: RACK MAGIC – Content Type # http://hokstad.com/rewriting-content-types-with-rack.html class RewriteContentType def initialize(app, map); @app, @map = app, map; end def call(env) res = @app.call(env) type = res[1]["Content-Type"] res[1]["Content-Type"] = @map[type] if @map.has_key?(type) res end end use RewriteContentType, {'application/json'=>'text/plain'} run Halcyon::Runner.new

Slide 25: RACK MAGIC – Reloader Automatically reload modified requirements. # uncomment for pretty web exception rendering # when testing in browser. # use Rack::ShowExceptions use Rack::Reloader run Halcyon::Runner.new Simple as that.

Slide 26: RACK MAGIC – Referrer Keep a log of referring links (if even set), or any other recordable data. http://hokstad.com/latest-referrers-using-rack-and-ruby.html Why reinvent the wheel?

Slide 27: DEMO

Slide 28: QUESTIONS?

Slide 29: RESOURCES HOMEPAGE http://halcyon.rubyforge.org/ GIT REPO http://github.com/mtodd/halcyon DOCS http://halcyon.rubyforge.org/docs/ IRC freenode.net #halcyon Jan Lenhardt's MountainWest http://mtnwestrubyconf2008.confreaks.com/ CouchDB Talk 10lehnardt.html

Slide 30: FIN

Slide 31: SEE ALSO CouchDB http://couchdb.com/ Jan Lenhardt's MountainWest http://mtnwestrubyconf2008.confreaks.com/10lehnardt.html CouchDB Talk