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
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
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
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
- 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 &#x2018;API World&#x2019;\n
- Thanks to our sponsors for providing us with the space\n
- Introduce yourself\n
- many options out there to choose from\n- We&#x2019;re going to focus on feature of rails not many people know about\n
- Convenient\n- Focus on your code rather than building a framework\n
- 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
- Might need to add / remove a few depending on your needs\n
- Might need to add / remove a few depending on your needs\n
- Might need to add / remove a few depending on your needs\n
- Might need to add / remove a few depending on your needs\n