SlideShare a Scribd company logo
1 of 47
2011:A Grape Odyssey
     (easy api’s using Grape)
Introduction


  Mike Hagedorn
  @mwhagedorn
In the beginning
In the beginning
In the end..

   Ends up a mess...

   So how do people deal
   with this? lead into next
In the end..

   Ends up a mess...

   So how do people deal
   with this? lead into next
In the end..

   Ends up a mess...

   So how do people deal
   with this? lead into next
Rails?
Rails?


• Too Much
Rails?


• Too Much
• Overlapping WebUI and “data”
  responsibilities
Sinatra?


• Too manual
Rack App?


• Even MORE manual
“Lagom”
“Lagom”

• Swedish for “just the right amount”
“Lagom”

• Swedish for “just the right amount”
• “Small things, loosely joined, written fast”
  - Justin Gehtland
“Lagom”

• Swedish for “just the right amount”
• “Small things, loosely joined, written fast”
  - Justin Gehtland
• Separation of concerns
“Lagom”

• Swedish for “just the right amount”
• “Small things, loosely joined, written fast”
  - Justin Gehtland
• Separation of concerns
• Testability, Scalability
Grape
Grape

• Generalized Rapid API Erector
Grape

• Generalized Rapid API Erector
• Grape is a REST-like API micro framework
Grape

• Generalized Rapid API Erector
• Grape is a REST-like API micro framework
• Heavily influenced by Sinatra
Grape

• Generalized Rapid API Erector
• Grape is a REST-like API micro framework
• Heavily influenced by Sinatra
• Ruby based
Hello World
Hello World
   require 'grape'

class Bar < Grape::API
  get 'hello' do
    {:hello =>'world'}
  end
end
Hello World
   require 'grape'

class Bar < Grape::API
  get 'hello' do
    {:hello =>'world'}
  end
end




                     >GET /hello

                     {“hello”:”world”}
JSON Serialization
JSON Serialization


• Automatically invokes #to_json on returns
JSON Serialization


• Automatically invokes #to_json on returns
• Other formats soon
Prefixing
Prefixing
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix "api"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end
end
Prefixing
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix "api"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end
end




                                         >GET /api/widgets/1
Prefixing
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix "api"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end
end




                                         >GET /api/widgets/1

                                         {“name”:”widget1”}
Prefixing
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix "api"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end
end




       >GET /api/widgets                 >GET /api/widgets/1

                                         {“name”:”widget1”}
Prefixing
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix "api"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end
end




       >GET /api/widgets                 >GET /api/widgets/1

       [{“name”:”widget1”}]              {“name”:”widget1”}
Versioning
   require 'grape'

module TestApp

  class Bar < Grape::API
                                   resource, namespace,
    prefix “api”                   group all synonyms here
    version "v2"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end
Versioning
   require 'grape'

module TestApp

  class Bar < Grape::API
                                   resource, namespace,
    prefix “api”                   group all synonyms here
    version "v2"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end




                               >GET /api/v2/widgets
Versioning
   require 'grape'

module TestApp

  class Bar < Grape::API
                                   resource, namespace,
    prefix “api”                   group all synonyms here
    version "v2"
    resource "widgets" do
      get do
        Widget.all
      end

      get ":id" do
        Widget.find(params[:id])
      end
    end
  end




                               >GET /api/v2/widgets

                               [{“name”:”widget1”}]
Basic Authentication
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix “api”
    version "v2"
    resource "widgets" do
      get do
         Widget.all
      end
    end
    namespace :admin do
       http_basic do |u,p|
          u == 'admin' && p == YOURPASSWORD
        end
       namespace 'metrics' do get do
          {:clicks => Click.count} end
        end
    end
  end
end




     OAuth soon...
Basic Authentication
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix “api”
    version "v2"
    resource "widgets" do
      get do
         Widget.all
      end
    end
    namespace :admin do
       http_basic do |u,p|
          u == 'admin' && p == YOURPASSWORD
        end
       namespace 'metrics' do get do
          {:clicks => Click.count} end
        end
    end
  end
end




     OAuth soon...
                                              admin:<password>
Basic Authentication
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix “api”
    version "v2"
    resource "widgets" do
      get do
         Widget.all
      end
    end
    namespace :admin do
       http_basic do |u,p|
          u == 'admin' && p == YOURPASSWORD
        end
       namespace 'metrics' do get do
          {:clicks => Click.count} end
        end
    end
  end
end




     OAuth soon...
                                              admin:<password>
                                              >GET /api/v2/admin
Basic Authentication
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix “api”
    version "v2"
    resource "widgets" do
      get do
         Widget.all
      end
    end
    namespace :admin do
       http_basic do |u,p|
          u == 'admin' && p == YOURPASSWORD
        end
       namespace 'metrics' do get do
          {:clicks => Click.count} end
        end
    end
  end
end




     OAuth soon...
                                              admin:<password>
                                              >GET /api/v2/admin

                                              {“clicks”:1234}
Basic Authentication
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix “api”
    version "v2"
    resource "widgets" do
      get do
         Widget.all
      end
    end
    namespace :admin do
       http_basic do |u,p|
          u == 'admin' && p == YOURPASSWORD
        end
       namespace 'metrics' do get do
          {:clicks => Click.count} end
        end
    end
  end
end




     OAuth soon...
                                              admin:<password>
         >GET /api/v2/admin
                                              >GET /api/v2/admin

                                              {“clicks”:1234}
Basic Authentication
    require 'grape'

module TestApp
  class Bar < Grape::API
    prefix “api”
    version "v2"
    resource "widgets" do
      get do
         Widget.all
      end
    end
    namespace :admin do
       http_basic do |u,p|
          u == 'admin' && p == YOURPASSWORD
        end
       namespace 'metrics' do get do
          {:clicks => Click.count} end
        end
    end
  end
end




     OAuth soon...
                                              admin:<password>
         >GET /api/v2/admin
                                              >GET /api/v2/admin
         401 Unauthorized
                                              {“clicks”:1234}
Status/Error Codes
     class MyAPI < Grape::API
  helpers do
     def current_user
        @current_user ||= User.find_by_single_use_token(params[:auth_token])
     end
  end
  get '/self' do
      error!("401 Unauthorized", 401) unless current_user
      current_user
    end
end
Status/Error Codes
     class MyAPI < Grape::API
  helpers do
     def current_user
        @current_user ||= User.find_by_single_use_token(params[:auth_token])
     end
  end
  get '/self' do
      error!("401 Unauthorized", 401) unless current_user
      current_user
    end
end




                              >GET /self?auth_token=BAD
Status/Error Codes
     class MyAPI < Grape::API
  helpers do
     def current_user
        @current_user ||= User.find_by_single_use_token(params[:auth_token])
     end
  end
  get '/self' do
      error!("401 Unauthorized", 401) unless current_user
      current_user
    end
end




                              >GET /self?auth_token=BAD

                              401 Unauthorized
Demo


• Extractinator

More Related Content

What's hot

Empowering the "mobile web"
Empowering the "mobile web"Empowering the "mobile web"
Empowering the "mobile web"Chris Mills
 
Modern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on RailsModern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on RailsJonathan Johnson
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Nordic APIs
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!Chris Mills
 
APIs, now and in the future
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the futureChris Mills
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageKrzysztof Bialek
 
Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014David M. Johnson
 
Bootiful Development with Spring Boot and React - UberConf 2018
Bootiful Development with Spring Boot and React - UberConf 2018Bootiful Development with Spring Boot and React - UberConf 2018
Bootiful Development with Spring Boot and React - UberConf 2018Matt Raible
 
Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015Matt Raible
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricksJavier Eguiluz
 
AtlasCamp 2015: Connect everywhere - Cloud and Server
AtlasCamp 2015: Connect everywhere - Cloud and ServerAtlasCamp 2015: Connect everywhere - Cloud and Server
AtlasCamp 2015: Connect everywhere - Cloud and ServerAtlassian
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen LjuSkills Matter
 
Cross-browser testing in the real world
Cross-browser testing in the real worldCross-browser testing in the real world
Cross-browser testing in the real worldMartin Kleppmann
 
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Matt Raible
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoRyan Weaver
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web appsChris Mills
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
React Native - Workshop
React Native - WorkshopReact Native - Workshop
React Native - WorkshopFellipe Chagas
 

What's hot (20)

Empowering the "mobile web"
Empowering the "mobile web"Empowering the "mobile web"
Empowering the "mobile web"
 
Modern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on RailsModern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on Rails
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!
 
APIs, now and in the future
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the future
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
 
Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014
 
Bootiful Development with Spring Boot and React - UberConf 2018
Bootiful Development with Spring Boot and React - UberConf 2018Bootiful Development with Spring Boot and React - UberConf 2018
Bootiful Development with Spring Boot and React - UberConf 2018
 
Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
Vuejs testing
Vuejs testingVuejs testing
Vuejs testing
 
AtlasCamp 2015: Connect everywhere - Cloud and Server
AtlasCamp 2015: Connect everywhere - Cloud and ServerAtlasCamp 2015: Connect everywhere - Cloud and Server
AtlasCamp 2015: Connect everywhere - Cloud and Server
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Cross-browser testing in the real world
Cross-browser testing in the real worldCross-browser testing in the real world
Cross-browser testing in the real world
 
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web apps
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
React Native - Workshop
React Native - WorkshopReact Native - Workshop
React Native - Workshop
 

Similar to 2011 a grape odyssey

Building RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeDaniel Doubrovkine
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsSami Ekblad
 
Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Shuji Watanabe
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Confneal_kemp
 
Api development with rails
Api development with railsApi development with rails
Api development with railsEdwin Cruz
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with RailsAll Things Open
 
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles ServiceAraport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Servicestevemock
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswanivvaswani
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
FiNCのWeb API開発事情
FiNCのWeb API開発事情FiNCのWeb API開発事情
FiNCのWeb API開発事情Fumiya Shinozuka
 
OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016Stephen Fink
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Google Cloud Endpointsによる API構築
Google Cloud Endpointsによる API構築Google Cloud Endpointsによる API構築
Google Cloud Endpointsによる API構築Keiji Ariyama
 
Warden Introduction
Warden IntroductionWarden Introduction
Warden Introductionhassox
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发shaokun
 

Similar to 2011 a grape odyssey (20)

Building RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ Grape
 
Ruby On Grape
Ruby On GrapeRuby On Grape
Ruby On Grape
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-ons
 
Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Serverless - Developers.IO 2019
Serverless - Developers.IO 2019
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Conf
 
Api development with rails
Api development with railsApi development with rails
Api development with rails
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles ServiceAraport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
 
Dancing with websocket
Dancing with websocketDancing with websocket
Dancing with websocket
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
FiNCのWeb API開発事情
FiNCのWeb API開発事情FiNCのWeb API開発事情
FiNCのWeb API開発事情
 
OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Google Cloud Endpointsによる API構築
Google Cloud Endpointsによる API構築Google Cloud Endpointsによる API構築
Google Cloud Endpointsによる API構築
 
Warden Introduction
Warden IntroductionWarden Introduction
Warden Introduction
 
Webauthn Tutorial
Webauthn TutorialWebauthn Tutorial
Webauthn Tutorial
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
BugBounty Tips.pdf
BugBounty Tips.pdfBugBounty Tips.pdf
BugBounty Tips.pdf
 

More from Mike Hagedorn

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesMike Hagedorn
 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of ThingsMike Hagedorn
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With FogMike Hagedorn
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyMike Hagedorn
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsMike Hagedorn
 

More from Mike Hagedorn (6)

Experienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New RolesExperienced Cloud Engineer Looking for New Roles
Experienced Cloud Engineer Looking for New Roles
 
Couchbase Talk
Couchbase TalkCouchbase Talk
Couchbase Talk
 
Hacking the Internet of Things
Hacking the Internet of ThingsHacking the Internet of Things
Hacking the Internet of Things
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With Fog
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.js
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

2011 a grape odyssey

  • 1. 2011:A Grape Odyssey (easy api’s using Grape)
  • 2. Introduction Mike Hagedorn @mwhagedorn
  • 5. In the end.. Ends up a mess... So how do people deal with this? lead into next
  • 6. In the end.. Ends up a mess... So how do people deal with this? lead into next
  • 7. In the end.. Ends up a mess... So how do people deal with this? lead into next
  • 10. Rails? • Too Much • Overlapping WebUI and “data” responsibilities
  • 12. Rack App? • Even MORE manual
  • 14. “Lagom” • Swedish for “just the right amount”
  • 15. “Lagom” • Swedish for “just the right amount” • “Small things, loosely joined, written fast” - Justin Gehtland
  • 16. “Lagom” • Swedish for “just the right amount” • “Small things, loosely joined, written fast” - Justin Gehtland • Separation of concerns
  • 17. “Lagom” • Swedish for “just the right amount” • “Small things, loosely joined, written fast” - Justin Gehtland • Separation of concerns • Testability, Scalability
  • 18. Grape
  • 20. Grape • Generalized Rapid API Erector • Grape is a REST-like API micro framework
  • 21. Grape • Generalized Rapid API Erector • Grape is a REST-like API micro framework • Heavily influenced by Sinatra
  • 22. Grape • Generalized Rapid API Erector • Grape is a REST-like API micro framework • Heavily influenced by Sinatra • Ruby based
  • 24. Hello World require 'grape' class Bar < Grape::API get 'hello' do {:hello =>'world'} end end
  • 25. Hello World require 'grape' class Bar < Grape::API get 'hello' do {:hello =>'world'} end end >GET /hello {“hello”:”world”}
  • 27. JSON Serialization • Automatically invokes #to_json on returns
  • 28. JSON Serialization • Automatically invokes #to_json on returns • Other formats soon
  • 30. Prefixing require 'grape' module TestApp class Bar < Grape::API prefix "api" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end end
  • 31. Prefixing require 'grape' module TestApp class Bar < Grape::API prefix "api" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end end >GET /api/widgets/1
  • 32. Prefixing require 'grape' module TestApp class Bar < Grape::API prefix "api" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end end >GET /api/widgets/1 {“name”:”widget1”}
  • 33. Prefixing require 'grape' module TestApp class Bar < Grape::API prefix "api" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end end >GET /api/widgets >GET /api/widgets/1 {“name”:”widget1”}
  • 34. Prefixing require 'grape' module TestApp class Bar < Grape::API prefix "api" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end end >GET /api/widgets >GET /api/widgets/1 [{“name”:”widget1”}] {“name”:”widget1”}
  • 35. Versioning require 'grape' module TestApp class Bar < Grape::API resource, namespace, prefix “api” group all synonyms here version "v2" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end
  • 36. Versioning require 'grape' module TestApp class Bar < Grape::API resource, namespace, prefix “api” group all synonyms here version "v2" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end >GET /api/v2/widgets
  • 37. Versioning require 'grape' module TestApp class Bar < Grape::API resource, namespace, prefix “api” group all synonyms here version "v2" resource "widgets" do get do Widget.all end get ":id" do Widget.find(params[:id]) end end end >GET /api/v2/widgets [{“name”:”widget1”}]
  • 38. Basic Authentication require 'grape' module TestApp class Bar < Grape::API prefix “api” version "v2" resource "widgets" do get do Widget.all end end namespace :admin do http_basic do |u,p| u == 'admin' && p == YOURPASSWORD end namespace 'metrics' do get do {:clicks => Click.count} end end end end end OAuth soon...
  • 39. Basic Authentication require 'grape' module TestApp class Bar < Grape::API prefix “api” version "v2" resource "widgets" do get do Widget.all end end namespace :admin do http_basic do |u,p| u == 'admin' && p == YOURPASSWORD end namespace 'metrics' do get do {:clicks => Click.count} end end end end end OAuth soon... admin:<password>
  • 40. Basic Authentication require 'grape' module TestApp class Bar < Grape::API prefix “api” version "v2" resource "widgets" do get do Widget.all end end namespace :admin do http_basic do |u,p| u == 'admin' && p == YOURPASSWORD end namespace 'metrics' do get do {:clicks => Click.count} end end end end end OAuth soon... admin:<password> >GET /api/v2/admin
  • 41. Basic Authentication require 'grape' module TestApp class Bar < Grape::API prefix “api” version "v2" resource "widgets" do get do Widget.all end end namespace :admin do http_basic do |u,p| u == 'admin' && p == YOURPASSWORD end namespace 'metrics' do get do {:clicks => Click.count} end end end end end OAuth soon... admin:<password> >GET /api/v2/admin {“clicks”:1234}
  • 42. Basic Authentication require 'grape' module TestApp class Bar < Grape::API prefix “api” version "v2" resource "widgets" do get do Widget.all end end namespace :admin do http_basic do |u,p| u == 'admin' && p == YOURPASSWORD end namespace 'metrics' do get do {:clicks => Click.count} end end end end end OAuth soon... admin:<password> >GET /api/v2/admin >GET /api/v2/admin {“clicks”:1234}
  • 43. Basic Authentication require 'grape' module TestApp class Bar < Grape::API prefix “api” version "v2" resource "widgets" do get do Widget.all end end namespace :admin do http_basic do |u,p| u == 'admin' && p == YOURPASSWORD end namespace 'metrics' do get do {:clicks => Click.count} end end end end end OAuth soon... admin:<password> >GET /api/v2/admin >GET /api/v2/admin 401 Unauthorized {“clicks”:1234}
  • 44. Status/Error Codes class MyAPI < Grape::API helpers do def current_user @current_user ||= User.find_by_single_use_token(params[:auth_token]) end end get '/self' do error!("401 Unauthorized", 401) unless current_user current_user end end
  • 45. Status/Error Codes class MyAPI < Grape::API helpers do def current_user @current_user ||= User.find_by_single_use_token(params[:auth_token]) end end get '/self' do error!("401 Unauthorized", 401) unless current_user current_user end end >GET /self?auth_token=BAD
  • 46. Status/Error Codes class MyAPI < Grape::API helpers do def current_user @current_user ||= User.find_by_single_use_token(params[:auth_token]) end end get '/self' do error!("401 Unauthorized", 401) unless current_user current_user end end >GET /self?auth_token=BAD 401 Unauthorized

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n