Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

The Grapes of Rapid (RubyConf 2010)

on

  • 4,200 views

Talk about Grape, a rapid API development framework for Ruby. Presented at RubyConf 2010.

Talk about Grape, a rapid API development framework for Ruby. Presented at RubyConf 2010.

Statistics

Views

Total Views
4,200
Views on SlideShare
3,911
Embed Views
289

Actions

Likes
7
Downloads
33
Comments
0

4 Embeds 289

http://francescoagati.wordpress.com 285
https://francescoagati.wordpress.com 2
http://localhost:3000 1
http://www.pearltrees.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

The Grapes of Rapid (RubyConf 2010) The Grapes of Rapid (RubyConf 2010) Presentation Transcript

  • The Grapes of Rapid Michael Bleigh, RubyConf 2010
  • @mbleigh @intridea
  • confask.heroku.com
  • This is not the talk I wanted.
  • CDD
  • Conference Driven Development
  • Deliver Me Promise
  • Motivation
  • Ruby makes hard things easy
  • But APIs still aren’t easy
  • APIs in Rails are too entangled
  • APIs in Sinatra are too manual
  • Why can’t APIs have their own framework?
  • #newtwitter
  • Grape
  • Generalized Rapid API Erector
  • Something that sounds like API... pe grap a e gravy
  • High Level
  • Built for ease of development.
  • Sinatra-inspired.
  • Just works.
  • What does it do?
  • What does it do now?
  • Basics
  • require 'grape' class MyAPI < Grape::API get 'hello' do {:hello => 'world'} end end GET /hello {“hello”:”world”}
  • JSON Serialization
  • With Returned Value... • Look for #serializable_hash • Look for #to_json • Then tries to encode the object directly • Other formats coming soon
  • Prefixing
  • class MyAPI < Grape::API prefix 'api' get 'hello' do {:hello => 'world'} end end GET /hello GET /api/hello 404 Not Found {“hello”:”world”}
  • Versioning
  • class MyAPI < Grape::API prefix 'api' version 'v1' get 'hello' do {:version => version} end end GET /api/v2/hello GET /api/v1/hello 404 API Version {“version”:”v1”} Not Found
  • Namespacing
  • class MyAPI < Grape::API namespace :admin do namespace 'metrics' do get do {:clicks => Click.count} end get '/:date' do {:clicks => Click.for_date(params[:date]).count} end end end end GET /admin/metrics {“clicks”:235343} GET /admin/metrics/2010-11-13 {“clicks”:5392}
  • Stackable Configuration
  • Basic Auth
  • class MyAPI < Grape::API get 'open' do "Hello." end namespace :admin do http_basic do |u,p| u == 'admin' && p == ENV['ADMIN_PASSWORD'] end namespace 'metrics' do get do {:clicks => Click.count} end end end end admin:somepassword GET /admin/metrics GET /admin/metrics 401 Unauthorized {“clicks”:235343}
  • Helpers
  • class MyAPI < Grape::API helpers do def current_user User.find_by_token(params[:token]) end end get '/me' do current_user end end GET /me?token=12ab312df {“screen_name”:”mbleigh”}
  • Erroring
  • class MyAPI < Grape::API helpers do def current_user @current_user ||= User.find_by_token(params[:token]) end end get '/me' do error!("401 Unauthorized", 401) unless current_user current_user end end GET /me?token=invalidtoken 401 Unauthorized
  • What will it do soon?
  • Documentation Generation
  • Content Negotiation
  • OAuth 1.0/2.0
  • Multiple Files
  • Plugin System
  • Vaporware
  • Streaming APIs
  • PubSubHubBub
  • Presenters
  • Rate Limiting
  • Internal API
  • ConfAsk: Grape In Action
  • Questions? gem install grape github.com/intridea/grape