SlideShare une entreprise Scribd logo
1  sur  26
http://www.rails.in.th

Developing API with Rails
Sponsors




http://www.artellectual.com   http://www.oozou.com
Who Am I

Sakchai (Zack) Siripanyawuth
   twitter: @artellectual
  developer at Artellectual
Options

•   LightRail - https://github.com/lightness/lightrail

•   RocketPants (i am not joking) - https://github.com/
    filtersquad/rocket_pants

•   Sinatra Mounted into a Rails App - http://
    www.sinatrarb.com/

•   Good Ol’ - ActionController::Base
Why Rails Metal
• Because its thinner
• Benefits of rails is a few lines of code away
• Less context switching (ie same
  conventions)
• Easy to do Hybrid Apps
• Modular
• No need to write Boilerplate Code
Something to keep in mind
VS
MODULES = [
      AbstractController::Layouts,
      AbstractController::Translation,
      AbstractController::AssetPaths,
      Helpers,
      HideActions,
      UrlFor,
      Redirecting,
      Rendering,
      Renderers::All,
      ConditionalGet,
      RackDelegation,
      Caching,
      MimeResponds,
      ImplicitRender,
      Cookies,
      Flash,
      RequestForgeryProtection,
      ForceSSL,
      Streaming,
                                                       VS
      DataStreaming,
      RecordIdentifier,
      HttpAuthentication::Basic::ControllerMethods,
      HttpAuthentication::Digest::ControllerMethods,
      HttpAuthentication::Token::ControllerMethods,
      AbstractController::Callbacks,
      Rescue,
      Instrumentation,
      ParamsWrapper
    ]
MODULES = [                                                 include   ActionController::Helpers
      AbstractController::Layouts,                          include   ActionController::Redirecting
      AbstractController::Translation,                      include   ActionController::Rendering
      AbstractController::AssetPaths,                       include   ActionController::Renderers::All
      Helpers,                                              include   ActionController::ConditionalGet
      HideActions,                                          include   ActionController::MimeResponds
      UrlFor,                                               include   ActionController::RequestForgeryProtection
      Redirecting,                                          include   ActionController::ForceSSL
      Rendering,                                            include   AbstractController::Callbacks
      Renderers::All,                                       include   ActionController::Instrumentation
      ConditionalGet,                                       include   ActionController::ParamsWrapper
      RackDelegation,                                       include   Devise::Controllers::Helpers
      Caching,
      MimeResponds,
      ImplicitRender,
      Cookies,
      Flash,
      RequestForgeryProtection,
      ForceSSL,
      Streaming,
                                                       VS
      DataStreaming,
      RecordIdentifier,
      HttpAuthentication::Basic::ControllerMethods,
      HttpAuthentication::Digest::ControllerMethods,
      HttpAuthentication::Token::ControllerMethods,
      AbstractController::Callbacks,
      Rescue,
      Instrumentation,
      ParamsWrapper
    ]
MODULES = [                                                 include   ActionController::Helpers
      AbstractController::Layouts,                          include   ActionController::Redirecting
      AbstractController::Translation,                      include   ActionController::Rendering
      AbstractController::AssetPaths,                       include   ActionController::Renderers::All
      Helpers,                                              include   ActionController::ConditionalGet
      HideActions,                                          include   ActionController::MimeResponds
      UrlFor,                                               include   ActionController::RequestForgeryProtection
      Redirecting,                                          include   ActionController::ForceSSL
      Rendering,                                            include   AbstractController::Callbacks
      Renderers::All,                                       include   ActionController::Instrumentation
      ConditionalGet,                                       include   ActionController::ParamsWrapper
      RackDelegation,                                       include   Devise::Controllers::Helpers
      Caching,
      MimeResponds,
      ImplicitRender,
      Cookies,
      Flash,
      RequestForgeryProtection,
      ForceSSL,
      Streaming,
                                                       VS
      DataStreaming,
      RecordIdentifier,
      HttpAuthentication::Basic::ControllerMethods,
      HttpAuthentication::Digest::ControllerMethods,
      HttpAuthentication::Token::ControllerMethods,
      AbstractController::Callbacks,
      Rescue,
      Instrumentation,
      ParamsWrapper
    ]




              28 Modules
MODULES = [                                                 include   ActionController::Helpers
      AbstractController::Layouts,                          include   ActionController::Redirecting
      AbstractController::Translation,                      include   ActionController::Rendering
      AbstractController::AssetPaths,                       include   ActionController::Renderers::All
      Helpers,                                              include   ActionController::ConditionalGet
      HideActions,                                          include   ActionController::MimeResponds
      UrlFor,                                               include   ActionController::RequestForgeryProtection
      Redirecting,                                          include   ActionController::ForceSSL
      Rendering,                                            include   AbstractController::Callbacks
      Renderers::All,                                       include   ActionController::Instrumentation
      ConditionalGet,                                       include   ActionController::ParamsWrapper
      RackDelegation,                                       include   Devise::Controllers::Helpers
      Caching,
      MimeResponds,
      ImplicitRender,
      Cookies,
      Flash,
      RequestForgeryProtection,
      ForceSSL,
      Streaming,
                                                       VS
      DataStreaming,
      RecordIdentifier,
      HttpAuthentication::Basic::ControllerMethods,
      HttpAuthentication::Digest::ControllerMethods,
      HttpAuthentication::Token::ControllerMethods,
      AbstractController::Callbacks,
      Rescue,
      Instrumentation,
      ParamsWrapper
    ]




              28 Modules                                              12 Modules
How much faster?
                    ActionController::Base
                    ActionController::Metal

             1200
                                     1200
              900

              600

              300
                      400
                0
                             Rails


                     not so fine print:
*take these numbers with a grain of salt / benchmark yourself
Let’s Code!
/app/controllers/application_controller.rb
/app/controllers/application_controller.rb


class ApplicationController < ActionController::Base
  # All kinds of magic
end
/app/controllers/api_controller.rb
/app/controllers/api_controller.rb
class ApiController < ActionController::Metal # inherit from Metal instead of Base
  include ActionController::Helpers
  include ActionController::Redirecting
  include ActionController::Rendering
  include ActionController::Renderers::All
  include ActionController::ConditionalGet

  # need this for responding to different types .json .xml etc...
  include ActionController::MimeResponds
  include ActionController::RequestForgeryProtection
  # need this if your using SSL
  include ActionController::ForceSSL
  include AbstractController::Callbacks
  # need this to build 'params'
  include ActionController::Instrumentation
  # need this for wrap_parameters
  include ActionController::ParamsWrapper
  include Devise::Controllers::Helpers

  # need make your ApiController aware of your routes
  include Rails.application.routes.url_helpers

  # tell the controller where to look for templates
  append_view_path "#{Rails.root}/app/views"

  # you need this to wrap the parameters correctly eg
  # { "person": { "name": "Zack", "email": "sakchai@artellectual.com", "twitter": "@artellectual" }}
  wrap_parameters format: [:json]

  # might not need this (depends on your client) rails bypasses automatically if client is not browser
  protect_from_forgery
end
config/routes.rb
config/routes.rb


namespace "api" do
  resources :contacts
  resources :comments
  resources :photos
end
config/routes.rb


namespace "api" do
  resources :contacts
  resources :comments
  resources :photos
end


       example:
config/routes.rb


   namespace "api" do
     resources :contacts
     resources :comments
     resources :photos
   end


           example:
www.greatapp.com/api/contacts
/app/controllers/api/contacts_controller.rb
/app/controllers/api/contacts_controller.rb




class Api::ContactsController < ApiController
  # more magic goes here
end
Lets look at Views

• RABL - https://github.com/nesquena/rabl
• jbuilder - https://github.com/rails/jbuilder
• jsonify - https://github.com/bsiggelkow/
  jsonify
Testing with json_spec
https://github.com/collectiveidea/json_spec
   describe "/contacts/:id.json" do
     before(:each) do
       get :show, id: @client.id, format: :json
     end

     it "should render the correct template for SHOW" do
       response.should render_template("api/contacts/show")
     end

     it "should render the correct attributes for contact" do
       response.body.should have_json_path("id")
       response.body.should have_json_path("first_name")
       response.body.should have_json_path("last_name")
       response.body.should have_json_path("type")
       response.body.should have_json_path("updated_at")
     end
   end
Thank You !

Contenu connexe

Tendances

Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparisonHiroshi Nakamura
 
Java Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application SecurityJava Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application SecurityIMC Institute
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisFastly
 
HTTP For the Good or the Bad
HTTP For the Good or the BadHTTP For the Good or the Bad
HTTP For the Good or the BadXavier Mertens
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring SessionDavid Gómez García
 
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Luciano Mammino
 
Security Checkpoints in Agile SDLC
Security Checkpoints in Agile SDLCSecurity Checkpoints in Agile SDLC
Security Checkpoints in Agile SDLCRahul Raghavan
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Philippe Gamache
 
Android webservices
Android webservicesAndroid webservices
Android webservicesKrazy Koder
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019Matt Raible
 
Ws security with opensource platform
Ws security with opensource platformWs security with opensource platform
Ws security with opensource platformPegasystems
 
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...Ontico
 
There and back again: A story of a s
There and back again: A story of a sThere and back again: A story of a s
There and back again: A story of a sColin Harrington
 
Dynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningDynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningSean Chittenden
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysisIbrahim Baliç
 
Make your application expressive
Make your application expressiveMake your application expressive
Make your application expressiveChristian Varela
 

Tendances (20)

Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 
Java Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application SecurityJava Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application Security
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
HTTP For the Good or the Bad
HTTP For the Good or the BadHTTP For the Good or the Bad
HTTP For the Good or the Bad
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring Session
 
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
 
Security Checkpoints in Agile SDLC
Security Checkpoints in Agile SDLCSecurity Checkpoints in Agile SDLC
Security Checkpoints in Agile SDLC
 
Testing NodeJS Security
Testing NodeJS SecurityTesting NodeJS Security
Testing NodeJS Security
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017
 
Servlet30 20081218
Servlet30 20081218Servlet30 20081218
Servlet30 20081218
 
Client side
Client sideClient side
Client side
 
Android webservices
Android webservicesAndroid webservices
Android webservices
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
 
Ws security with opensource platform
Ws security with opensource platformWs security with opensource platform
Ws security with opensource platform
 
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
 
There and back again: A story of a s
There and back again: A story of a sThere and back again: A story of a s
There and back again: A story of a s
 
Dynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningDynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency Planning
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysis
 
Make your application expressive
Make your application expressiveMake your application expressive
Make your application expressive
 

Similaire à Developing api with rails metal

Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on RailsMark Menard
 
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarang
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad SarangNull Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarang
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarangnullowaspmumbai
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011Fabio Akita
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do railsDNAD
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application ServerPhil Windley
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Patternmaddinapudi
 
Nginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksNginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksAdam Wiggins
 
Rohit yadav cloud stack internals
Rohit yadav   cloud stack internalsRohit yadav   cloud stack internals
Rohit yadav cloud stack internalsShapeBlue
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Plataformatec
 
Foomo / Zugspitze Presentation
Foomo / Zugspitze PresentationFoomo / Zugspitze Presentation
Foomo / Zugspitze Presentationweareinteractive
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009bturnbull
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Webnickmbailey
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using GoCloudOps2005
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Massimo Oliviero
 
Dynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andiDynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andiDynatrace
 

Similaire à Developing api with rails metal (20)

Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on Rails
 
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarang
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad SarangNull Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarang
Null Mumbai 14th May Lesser Known Webapp attacks by Ninad Sarang
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
 
Nginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksNginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP Tricks
 
Rohit yadav cloud stack internals
Rohit yadav   cloud stack internalsRohit yadav   cloud stack internals
Rohit yadav cloud stack internals
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
Foomo / Zugspitze Presentation
Foomo / Zugspitze PresentationFoomo / Zugspitze Presentation
Foomo / Zugspitze Presentation
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Web
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using Go
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
Rack
RackRack
Rack
 
Dynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andiDynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left &amp; self-healing a performance clinic with andi
 

Dernier

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Dernier (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Developing api with rails metal

  • 3. Who Am I Sakchai (Zack) Siripanyawuth twitter: @artellectual developer at Artellectual
  • 4. Options • LightRail - https://github.com/lightness/lightrail • RocketPants (i am not joking) - https://github.com/ filtersquad/rocket_pants • Sinatra Mounted into a Rails App - http:// www.sinatrarb.com/ • Good Ol’ - ActionController::Base
  • 5. Why Rails Metal • Because its thinner • Benefits of rails is a few lines of code away • Less context switching (ie same conventions) • Easy to do Hybrid Apps • Modular • No need to write Boilerplate Code
  • 7. VS
  • 8. MODULES = [ AbstractController::Layouts, AbstractController::Translation, AbstractController::AssetPaths, Helpers, HideActions, UrlFor, Redirecting, Rendering, Renderers::All, ConditionalGet, RackDelegation, Caching, MimeResponds, ImplicitRender, Cookies, Flash, RequestForgeryProtection, ForceSSL, Streaming, VS DataStreaming, RecordIdentifier, HttpAuthentication::Basic::ControllerMethods, HttpAuthentication::Digest::ControllerMethods, HttpAuthentication::Token::ControllerMethods, AbstractController::Callbacks, Rescue, Instrumentation, ParamsWrapper ]
  • 9. MODULES = [ include ActionController::Helpers AbstractController::Layouts, include ActionController::Redirecting AbstractController::Translation, include ActionController::Rendering AbstractController::AssetPaths, include ActionController::Renderers::All Helpers, include ActionController::ConditionalGet HideActions, include ActionController::MimeResponds UrlFor, include ActionController::RequestForgeryProtection Redirecting, include ActionController::ForceSSL Rendering, include AbstractController::Callbacks Renderers::All, include ActionController::Instrumentation ConditionalGet, include ActionController::ParamsWrapper RackDelegation, include Devise::Controllers::Helpers Caching, MimeResponds, ImplicitRender, Cookies, Flash, RequestForgeryProtection, ForceSSL, Streaming, VS DataStreaming, RecordIdentifier, HttpAuthentication::Basic::ControllerMethods, HttpAuthentication::Digest::ControllerMethods, HttpAuthentication::Token::ControllerMethods, AbstractController::Callbacks, Rescue, Instrumentation, ParamsWrapper ]
  • 10. MODULES = [ include ActionController::Helpers AbstractController::Layouts, include ActionController::Redirecting AbstractController::Translation, include ActionController::Rendering AbstractController::AssetPaths, include ActionController::Renderers::All Helpers, include ActionController::ConditionalGet HideActions, include ActionController::MimeResponds UrlFor, include ActionController::RequestForgeryProtection Redirecting, include ActionController::ForceSSL Rendering, include AbstractController::Callbacks Renderers::All, include ActionController::Instrumentation ConditionalGet, include ActionController::ParamsWrapper RackDelegation, include Devise::Controllers::Helpers Caching, MimeResponds, ImplicitRender, Cookies, Flash, RequestForgeryProtection, ForceSSL, Streaming, VS DataStreaming, RecordIdentifier, HttpAuthentication::Basic::ControllerMethods, HttpAuthentication::Digest::ControllerMethods, HttpAuthentication::Token::ControllerMethods, AbstractController::Callbacks, Rescue, Instrumentation, ParamsWrapper ] 28 Modules
  • 11. MODULES = [ include ActionController::Helpers AbstractController::Layouts, include ActionController::Redirecting AbstractController::Translation, include ActionController::Rendering AbstractController::AssetPaths, include ActionController::Renderers::All Helpers, include ActionController::ConditionalGet HideActions, include ActionController::MimeResponds UrlFor, include ActionController::RequestForgeryProtection Redirecting, include ActionController::ForceSSL Rendering, include AbstractController::Callbacks Renderers::All, include ActionController::Instrumentation ConditionalGet, include ActionController::ParamsWrapper RackDelegation, include Devise::Controllers::Helpers Caching, MimeResponds, ImplicitRender, Cookies, Flash, RequestForgeryProtection, ForceSSL, Streaming, VS DataStreaming, RecordIdentifier, HttpAuthentication::Basic::ControllerMethods, HttpAuthentication::Digest::ControllerMethods, HttpAuthentication::Token::ControllerMethods, AbstractController::Callbacks, Rescue, Instrumentation, ParamsWrapper ] 28 Modules 12 Modules
  • 12. How much faster? ActionController::Base ActionController::Metal 1200 1200 900 600 300 400 0 Rails not so fine print: *take these numbers with a grain of salt / benchmark yourself
  • 15. /app/controllers/application_controller.rb class ApplicationController < ActionController::Base # All kinds of magic end
  • 17. /app/controllers/api_controller.rb class ApiController < ActionController::Metal # inherit from Metal instead of Base include ActionController::Helpers include ActionController::Redirecting include ActionController::Rendering include ActionController::Renderers::All include ActionController::ConditionalGet # need this for responding to different types .json .xml etc... include ActionController::MimeResponds include ActionController::RequestForgeryProtection # need this if your using SSL include ActionController::ForceSSL include AbstractController::Callbacks # need this to build 'params' include ActionController::Instrumentation # need this for wrap_parameters include ActionController::ParamsWrapper include Devise::Controllers::Helpers # need make your ApiController aware of your routes include Rails.application.routes.url_helpers # tell the controller where to look for templates append_view_path "#{Rails.root}/app/views" # you need this to wrap the parameters correctly eg # { "person": { "name": "Zack", "email": "sakchai@artellectual.com", "twitter": "@artellectual" }} wrap_parameters format: [:json] # might not need this (depends on your client) rails bypasses automatically if client is not browser protect_from_forgery end
  • 19. config/routes.rb namespace "api" do resources :contacts resources :comments resources :photos end
  • 20. config/routes.rb namespace "api" do resources :contacts resources :comments resources :photos end example:
  • 21. config/routes.rb namespace "api" do resources :contacts resources :comments resources :photos end example: www.greatapp.com/api/contacts
  • 24. Lets look at Views • RABL - https://github.com/nesquena/rabl • jbuilder - https://github.com/rails/jbuilder • jsonify - https://github.com/bsiggelkow/ jsonify
  • 25. Testing with json_spec https://github.com/collectiveidea/json_spec describe "/contacts/:id.json" do before(:each) do get :show, id: @client.id, format: :json end it "should render the correct template for SHOW" do response.should render_template("api/contacts/show") end it "should render the correct attributes for contact" do response.body.should have_json_path("id") response.body.should have_json_path("first_name") response.body.should have_json_path("last_name") response.body.should have_json_path("type") response.body.should have_json_path("updated_at") end end

Notes de l'éditeur

  1. - Thanks everyone for coming\n- Goals for our Group\n- Web Development is shifting to Rich Client Apps\n- Rise of Javascript Libraries / Frameworks\n- Pattern for developing Javascript MVC is very similar to iOS / Android apps\n- Rails is evolving\n- Active Discussions in rails community on how to handle this &amp;#x2018;API World&amp;#x2019;\n
  2. - Thanks to our sponsors for providing us with the space\n
  3. - Introduce yourself\n
  4. - many options out there to choose from\n- We&amp;#x2019;re going to focus on feature of rails not many people know about\n
  5. - Convenient\n- Focus on your code rather than building a framework\n
  6. - People forget that security is important\n- Do you really want to implement security features yourself?\n- with things like Node / Sinatra its up to you to handle the security\n
  7. - Might need to add / remove a few depending on your needs\n
  8. - Might need to add / remove a few depending on your needs\n
  9. - Might need to add / remove a few depending on your needs\n
  10. - Might need to add / remove a few depending on your needs\n
  11. \n
  12. \n
  13. \n
  14. - explain the code\n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n