SlideShare uma empresa Scribd logo
1 de 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 !

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Último (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

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

Notas do Editor

  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