SlideShare a Scribd company logo
1 of 113
Download to read offline
Rails APIs
Monday, February 25, 13
@markbates
Monday, February 25, 13
Monday, February 25, 13
Monday, February 25, 13
http://www.metacasts.tv
                            CONFOO2013


Monday, February 25, 13
Rails APIs
Monday, February 25, 13
Rails APIs
Monday, February 25, 13
e b APIs
                          Rails
                          W
Monday, February 25, 13
you’re probably
                           doing it wrong

Monday, February 25, 13
Don’t Panic!
Monday, February 25, 13
most APIs are an
                           after thought

Monday, February 25, 13
we can prevent
                               that!

Monday, February 25, 13
3 simple rules for
                           building an API

Monday, February 25, 13
1. consume your
                               own API

Monday, February 25, 13
2. document your
                                 API

Monday, February 25, 13
3. version your
                                API

Monday, February 25, 13
building the API

Monday, February 25, 13
SOA
Monday, February 25, 13
Service Oriented
                            Architecture

Monday, February 25, 13
SOA Pros




Monday, February 25, 13
SOA Pros

                          •   Scales Easily




Monday, February 25, 13
SOA Pros

                          •   Scales Easily

                          •   Separate Concerns/Very Clean




Monday, February 25, 13
SOA Pros

                          •   Scales Easily

                          •   Separate Concerns/Very Clean

                          •   Can be easier to maintain




Monday, February 25, 13
SOA Pros

                          •   Scales Easily

                          •   Separate Concerns/Very Clean

                          •   Can be easier to maintain

                          •   Solid Architecture




Monday, February 25, 13
SOA Pros

                          •   Scales Easily

                          •   Separate Concerns/Very Clean

                          •   Can be easier to maintain

                          •   Solid Architecture

                          •   Easier to refactor/rebuild


Monday, February 25, 13
SOA Cons




Monday, February 25, 13
SOA Cons

                          •   Can be more difficult to maintain




Monday, February 25, 13
SOA Cons

                          •   Can be more difficult to maintain

                          •   More complex deploys




Monday, February 25, 13
SOA Cons

                          •   Can be more difficult to maintain

                          •   More complex deploys

                          •   Managing several applications




Monday, February 25, 13
SOA Cons

                          •   Can be more difficult to maintain

                          •   More complex deploys

                          •   Managing several applications

                          •   Potential for ‘out-of-sync’ apps




Monday, February 25, 13
SOA Cons

                          •   Can be more difficult to maintain

                          •   More complex deploys

                          •   Managing several applications

                          •   Potential for ‘out-of-sync’ apps

                          •   More difficult to test integration


Monday, February 25, 13
API   Client




Monday, February 25, 13
Client

                          API

                                Client




Monday, February 25, 13
Client




                          API   Client




                                Client




Monday, February 25, 13
Client
                          Service 1



                          Service 2   Client



                          Service 3
                                      Client




Monday, February 25, 13
a quick detour

Monday, February 25, 13
Rails encourages
                          poor API design!

Monday, February 25, 13
Monday, February 25, 13
 	
  #	
  POST	
  /todos
                                                                                                       	
  	
  #	
  POST	
  /todos.json
                                                                                                       	
  	
  def	
  create
                          class	
  TodosController	
  <	
  ApplicationController                       	
  	
  	
  	
  @todo	
  =	
  Todo.new(params[:todo])
                          	
  	
  #	
  GET	
  /todos                                                   	
  
                          	
  	
  #	
  GET	
  /todos.json                                              	
  	
  	
  	
  respond_to	
  do	
  |format|
                          	
  	
  def	
  index                                                         	
  	
  	
  	
  	
  	
  if	
  @todo.save
                          	
  	
  	
  	
  @todos	
  =	
  Todo.all                                      	
  	
  	
  	
  	
  	
  	
  	
  format.html	
  {	
  redirect_to	
  @todo,	
  notice:	
  'Todo	
  was	
  successfully	
  created.'	
  }
                          	
                                                                           	
  	
  	
  	
  	
  	
  	
  	
  format.json	
  {	
  render	
  json:	
  @todo,	
  status:	
  :created,	
  location:	
  @todo	
  }
                          	
  	
  	
  	
  respond_to	
  do	
  |format|                                 	
  	
  	
  	
  	
  	
  else
                          	
  	
  	
  	
  	
  	
  format.html	
  #	
  index.html.erb                   	
  	
  	
  	
  	
  	
  	
  	
  format.html	
  {	
  render	
  action:	
  "new"	
  }
                          	
  	
  	
  	
  	
  	
  format.json	
  {	
  render	
  json:	
  @todos	
  }   	
  	
  	
  	
  	
  	
  	
  	
  format.json	
  {	
  render	
  json:	
  @todo.errors,	
  status:	
  :unprocessable_entity	
  }
                          	
  	
  	
  	
  end                                                          	
  	
  	
  	
  	
  	
  end
                          	
  	
  end                                                                  	
  	
  	
  	
  end
                          	
                                                                           	
  	
  end
                          	
  	
  #	
  GET	
  /todos/1                                                 	
  
                          	
  	
  #	
  GET	
  /todos/1.json                                            	
  	
  #	
  PUT	
  /todos/1
                          	
  	
  def	
  show                                                          	
  	
  #	
  PUT	
  /todos/1.json
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])                         	
  	
  def	
  update
                          	
                                                                           	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  	
  	
  	
  respond_to	
  do	
  |format|                                 	
  
                          	
  	
  	
  	
  	
  	
  format.html	
  #	
  show.html.erb                    	
  	
  	
  	
  respond_to	
  do	
  |format|
                          	
  	
  	
  	
  	
  	
  format.json	
  {	
  render	
  json:	
  @todo	
  }    	
  	
  	
  	
  	
  	
  if	
  @todo.update_attributes(params[:todo])
                          	
  	
  	
  	
  end                                                          	
  	
  	
  	
  	
  	
  	
  	
  format.html	
  {	
  redirect_to	
  @todo,	
  notice:	
  'Todo	
  was	
  successfully	
  updated.'	
  }
                          	
  	
  end                                                                  	
  	
  	
  	
  	
  	
  	
  	
  format.json	
  {	
  head	
  :no_content	
  }
                          	
                                                                           	
  	
  	
  	
  	
  	
  else
                          	
  	
  #	
  GET	
  /todos/new                                               	
  	
  	
  	
  	
  	
  	
  	
  format.html	
  {	
  render	
  action:	
  "edit"	
  }
                          	
  	
  #	
  GET	
  /todos/new.json                                          	
  	
  	
  	
  	
  	
  	
  	
  format.json	
  {	
  render	
  json:	
  @todo.errors,	
  status:	
  :unprocessable_entity	
  }
                          	
  	
  def	
  new                                                           	
  	
  	
  	
  	
  	
  end
                          	
  	
  	
  	
  @todo	
  =	
  Todo.new                                       	
  	
  	
  	
  end
                          	
                                                                           	
  	
  end
                          	
  	
  	
  	
  respond_to	
  do	
  |format|                                 	
  
                          	
  	
  	
  	
  	
  	
  format.html	
  #	
  new.html.erb                     	
  	
  #	
  DELETE	
  /todos/1
                          	
  	
  	
  	
  	
  	
  format.json	
  {	
  render	
  json:	
  @todo	
  }    	
  	
  #	
  DELETE	
  /todos/1.json
                          	
  	
  	
  	
  end                                                          	
  	
  def	
  destroy
                          	
  	
  end                                                                  	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
                                                                           	
  	
  	
  	
  @todo.destroy
                          	
  	
  #	
  GET	
  /todos/1/edit                                            	
  
                          	
  	
  def	
  edit                                                          	
  	
  	
  	
  respond_to	
  do	
  |format|
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])                         	
  	
  	
  	
  	
  	
  format.html	
  {	
  redirect_to	
  todos_url	
  }
                          	
  	
  end                                                                  	
  	
  	
  	
  	
  	
  format.json	
  {	
  head	
  :no_content	
  }
                                                                                                       	
  	
  	
  	
  end
                                                                                                       	
  	
  end
                                                                                                       end




Monday, February 25, 13
Don’t Scaffold!

Monday, February 25, 13
Monday, February 25, 13
class	
  TodosController	
  <	
  ApplicationController
                          	
  
                          	
  	
  def	
  index
                          	
  	
  	
  	
  @todos	
  =	
  Todo.all
                          	
  	
  end
                          	
  
                          	
  	
  def	
  show
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  	
  end
                          	
  
                          	
  	
  def	
  new
                          	
  	
  	
  	
  @todo	
  =	
  Todo.new
                          	
  	
  end
                          	
  
                          	
  	
  def	
  edit
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  	
  end
                          	
  
                          	
  	
  def	
  create
                          	
  	
  	
  	
  @todo	
  =	
  Todo.new(params[:todo])
                          	
  	
  	
  	
  if	
  @todo.save
                          	
  	
  	
  	
  	
  	
  redirect_to	
  @todo,	
  notice:	
  'Todo	
  was	
  successfully	
  created.'
                          	
  	
  	
  	
  else
                          	
  	
  	
  	
  	
  	
  render	
  action:	
  "new"
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  
                          	
  	
  def	
  update
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  
                          	
  	
  	
  	
  if	
  @todo.update_attributes(params[:todo])
                          	
  	
  	
  	
  	
  	
  redirect_to	
  @todo,	
  notice:	
  'Todo	
  was	
  successfully	
  updated.'
                          	
  	
  	
  	
  else
                          	
  	
  	
  	
  	
  	
  render	
  action:	
  "edit"
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  
                          	
  	
  def	
  destroy
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  	
  	
  	
  @todo.destroy
                          	
  	
  	
  	
  redirect_to	
  todos_path,	
  notice:	
  'Todo	
  was	
  successfully	
  destroyed.'
                          	
  	
  end
                          end




Monday, February 25, 13
class	
  TodosController	
  <	
  ApplicationController
                          	
  	
  inherit_resources
                          end




Monday, February 25, 13
Inherited Resources
                             https://github.com/josevalim/inherited_resources




Monday, February 25, 13
Monday, February 25, 13
class	
  Api::V1::TodosController	
  <	
  ApplicationController
                          	
  	
  respond_to	
  :json
                          	
  
                          	
  	
  before_filter	
  do
                          	
  	
  	
  	
  request.format	
  =	
  :json
                          	
  	
  end
                          	
  
                          	
  	
  def	
  index
                          	
  	
  	
  	
  @todos	
  =	
  Todo.all
                          	
  	
  	
  	
  respond_with	
  @todos
                          	
  	
  end
                          	
  
                          	
  	
  def	
  show
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  	
  	
  	
  respond_with	
  @todo
                          	
  	
  end
                          	
  
                          	
  	
  def	
  create
                          	
  	
  	
  	
  @todo	
  =	
  Todo.new(params[:todo])
                          	
  	
  	
  	
  if	
  @todo.save
                          	
  	
  	
  	
  	
  	
  respond_with	
  @todo
                          	
  	
  	
  	
  else
                          	
  	
  	
  	
  	
  	
  render	
  json:	
  @todo.errors,	
  status:	
  :unprocessable_entity
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  
                          	
  	
  def	
  update
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  
                          	
  	
  	
  	
  if	
  @todo.update_attributes(params[:todo])
                          	
  	
  	
  	
  	
  	
  respond_with	
  @todo
                          	
  	
  	
  	
  else
                          	
  	
  	
  	
  	
  	
  render	
  json:	
  @todo.errors,	
  status:	
  :unprocessable_entity
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  
                          	
  	
  def	
  destroy
                          	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                          	
  	
  	
  	
  @todo.destroy
                          	
  	
  	
  	
  head	
  :no_content
                          	
  	
  end
                          end




Monday, February 25, 13
version your API!
                            Api::V1::TodosController
                                  /api/v1/todos




Monday, February 25, 13
i prefer URL
                            versioning

Monday, February 25, 13
others prefer
                          header versioning

Monday, February 25, 13
just pick one and
                            stick with it!

Monday, February 25, 13
SOA Review




Monday, February 25, 13
SOA Review


                          •   We’ve cleaned up our code




Monday, February 25, 13
SOA Review


                          •   We’ve cleaned up our code

                          •   We know the API Works




Monday, February 25, 13
SOA Review


                          •   We’ve cleaned up our code

                          •   We know the API Works

                          •   We’re now in a good place to scale




Monday, February 25, 13
consuming the API

Monday, February 25, 13
don’t use
                          Rails views

Monday, February 25, 13
JavaScript
Monday, February 25, 13
CORS
Monday, February 25, 13
Cross-origin
                          Resource Sharing

Monday, February 25, 13
rack-cors
                          https://github.com/cyu/rack-cors




Monday, February 25, 13
module	
  YourApp
                          	
  	
  class	
  Application	
  <	
  Rails::Application
                          	
  
                          	
  	
  #	
  ...
                          	
  
                          	
  	
  config.middleware.use	
  Rack::Cors	
  do
                          	
  	
  	
  	
  allow	
  do
                          	
  	
  	
  	
  	
  	
  origins	
  '*'
                          	
  	
  	
  	
  	
  	
  resource	
  '*',	
  headers:	
  :any,	
  
                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  methods:	
  [:get,	
  :post,	
  :put,	
  :delete,	
  :options]
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  	
  
                          end




Monday, February 25, 13
JavaScript Pros




Monday, February 25, 13
JavaScript Pros

                          •   Scales Easily/Pushes processing to client side




Monday, February 25, 13
JavaScript Pros

                          •   Scales Easily/Pushes processing to client side

                          •   Separate Concerns/Very Clean




Monday, February 25, 13
JavaScript Pros

                          •   Scales Easily/Pushes processing to client side

                          •   Separate Concerns/Very Clean

                          •   Can be easier to maintain




Monday, February 25, 13
JavaScript Pros

                          •   Scales Easily/Pushes processing to client side

                          •   Separate Concerns/Very Clean

                          •   Can be easier to maintain

                          •   “Responsive/Native” feel for clients




Monday, February 25, 13
JavaScript Pros

                          •   Scales Easily/Pushes processing to client side

                          •   Separate Concerns/Very Clean

                          •   Can be easier to maintain

                          •   “Responsive/Native” feel for clients

                          •   Easily consumes your API


Monday, February 25, 13
JavaScript Cons




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain

                          •   Multiple languages (backend/front-end)




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain

                          •   Multiple languages (backend/front-end)

                          •   Difficult to test integration




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain

                          •   Multiple languages (backend/front-end)

                          •   Difficult to test integration

                          •   JavaScript




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain

                          •   Multiple languages (backend/front-end)

                          •   Difficult to test integration

                          •   JavaScript

                          •   Paradigm shift in architecture




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain         •   Accessibility issues

                          •   Multiple languages (backend/front-end)

                          •   Difficult to test integration

                          •   JavaScript

                          •   Paradigm shift in architecture




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain         •   Accessibility issues

                          •   Multiple languages (backend/front-end)   •   SEO concerns

                          •   Difficult to test integration

                          •   JavaScript

                          •   Paradigm shift in architecture




Monday, February 25, 13
JavaScript Cons
                          •   Can be more difficult to maintain         •   Accessibility issues

                          •   Multiple languages (backend/front-end)   •   SEO concerns

                          •   Difficult to test integration             •   !!Internet Explorer!!

                          •   JavaScript

                          •   Paradigm shift in architecture




Monday, February 25, 13
pick a
                          framework
Monday, February 25, 13
don’t just
                          use jQuery
Monday, February 25, 13
the big
                           three
Monday, February 25, 13
Backbone.js



                            http://backbonejs.org/


Monday, February 25, 13
ember



                          http://emberjs.com/


Monday, February 25, 13
Angular.js



                            http://angularjs.org/


Monday, February 25, 13
i can’t use
                          JavaScript

Monday, February 25, 13
2 approaches
Monday, February 25, 13
“compiled” sites

Monday, February 25, 13
build your own
                          API library (and
                          open source it!)
Monday, February 25, 13
Monday, February 25, 13
class	
  TodosController	
  <	
  ApplicationController
                          	
  
                          	
  	
  def	
  index
                          	
  	
  	
  	
  @todos	
  =	
  ApiLib::Todo.all
                          	
  	
  end
                          	
  
                          	
  	
  def	
  show
                          	
  	
  	
  	
  @todo	
  =	
  ApiLib::Todo.find(params[:id])
                          	
  	
  end
                          	
  
                          	
  	
  def	
  new
                          	
  	
  	
  	
  @todo	
  =	
  ApiLib::Todo.new
                          	
  	
  end
                          	
  
                          	
  	
  def	
  edit
                          	
  	
  	
  	
  @todo	
  =	
  ApiLib::Todo.find(params[:id])
                          	
  	
  end
                          	
  
                          	
  	
  def	
  create
                          	
  	
  	
  	
  @todo	
  =	
  ApiLib::Todo.new(params[:todo])
                          	
  	
  	
  	
  if	
  @todo.save
                          	
  	
  	
  	
  	
  	
  redirect_to	
  @todo,	
  notice:	
  'Todo	
  was	
  successfully	
  created.'
                          	
  	
  	
  	
  else
                          	
  	
  	
  	
  	
  	
  render	
  action:	
  "new"
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  
                          	
  	
  def	
  update
                          	
  	
  	
  	
  @todo	
  =	
  ApiLib::Todo.find(params[:id])
                          	
  
                          	
  	
  	
  	
  if	
  @todo.update_attributes(params[:todo])
                          	
  	
  	
  	
  	
  	
  redirect_to	
  @todo,	
  notice:	
  'Todo	
  was	
  successfully	
  updated.'
                          	
  	
  	
  	
  else
                          	
  	
  	
  	
  	
  	
  render	
  action:	
  "edit"
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  
                          	
  	
  def	
  destroy
                          	
  	
  	
  	
  @todo	
  =	
  ApiLib::Todo.find(params[:id])
                          	
  	
  	
  	
  @todo.destroy
                          	
  	
  	
  	
  redirect_to	
  todos_path,	
  notice:	
  'Todo	
  was	
  successfully	
  destroyed.'
                          	
  	
  end
                          end




Monday, February 25, 13
hey! there is
                          duplicate* code
                                now
Monday, February 25, 13
is there? or did we
                              just move it
                                around?
Monday, February 25, 13
Todo became ApiLib::Todo



Monday, February 25, 13
we now have a
                             reference
                          implementation
Monday, February 25, 13
make sure
                          to cache!!
Monday, February 25, 13
The Hack
Monday, February 25, 13
Please don’t
                            do this!

Monday, February 25, 13
I’m Serious.
Monday, February 25, 13
Don’t use
                          this hack!

Monday, February 25, 13
I probably shouldn’t
                            even show you it.

Monday, February 25, 13
Ok, I’ll show you,
                            but don’t tell
                          people where you
                              heard it.
Monday, February 25, 13
Monday, February 25, 13
class	
  TodosController	
  <	
  ApplicationController
                          	
  
                          	
  	
  def	
  index
                          	
  	
  	
  	
  res	
  =	
  Api::V1::TodosController.action(:index).call(env)
                          	
  	
  	
  	
  @todos	
  =	
  JSON.parse(res[2].body).map	
  do	
  |data|
                          	
  	
  	
  	
  	
  	
  OpenStruct.new(data)
                          	
  	
  	
  	
  end
                          	
  	
  end
                          	
  
                          end




Monday, February 25, 13
projects
                          worth noting
Monday, February 25, 13
rails-api
Monday, February 25, 13
Monday, February 25, 13
api_doc
Monday, February 25, 13
Monday, February 25, 13
Monday, February 25, 13
Final Thoughts




Monday, February 25, 13
Final Thoughts

                          •   Consume your API




Monday, February 25, 13
Final Thoughts

                          •   Consume your API

                          •   Version your API




Monday, February 25, 13
Final Thoughts

                          •   Consume your API

                          •   Version your API

                          •   Document your API




Monday, February 25, 13
Final Thoughts

                          •   Consume your API

                          •   Version your API

                          •   Document your API

                          •   Did I mention consume your own API?



Monday, February 25, 13
Thank You
                          http://www.metacasts.tv
                            CONFOO2013
                                @markbates
Monday, February 25, 13

More Related Content

Similar to Building an API in Rails without Realizing It

WordPress for Beginners - YES Montreal
WordPress for Beginners - YES MontrealWordPress for Beginners - YES Montreal
WordPress for Beginners - YES MontrealKathryn Presner
 
Practical Search in the Cloud - By Marc Krellenstein
Practical Search in the Cloud - By Marc KrellensteinPractical Search in the Cloud - By Marc Krellenstein
Practical Search in the Cloud - By Marc Krellensteinlucenerevolution
 
Introduction to jQuery Mobile
Introduction to jQuery MobileIntroduction to jQuery Mobile
Introduction to jQuery MobileTroy Miles
 
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)Rick. Bahague
 

Similar to Building an API in Rails without Realizing It (6)

WordPress for Beginners - YES Montreal
WordPress for Beginners - YES MontrealWordPress for Beginners - YES Montreal
WordPress for Beginners - YES Montreal
 
RabbitMQ Hands On
RabbitMQ Hands OnRabbitMQ Hands On
RabbitMQ Hands On
 
Practical Search in the Cloud - By Marc Krellenstein
Practical Search in the Cloud - By Marc KrellensteinPractical Search in the Cloud - By Marc Krellenstein
Practical Search in the Cloud - By Marc Krellenstein
 
Introduction to jQuery Mobile
Introduction to jQuery MobileIntroduction to jQuery Mobile
Introduction to jQuery Mobile
 
RoR app for dummies
RoR app for dummiesRoR app for dummies
RoR app for dummies
 
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
Drupal campmanila 2012 (Responsive Web in Drupal with Omega Theme)
 

More from Mark

Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web AppsMark
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js FundamentalsMark
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the RubyistMark
 
Mangling Ruby with TracePoint
Mangling Ruby with TracePointMangling Ruby with TracePoint
Mangling Ruby with TracePointMark
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsMark
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTestMark
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTestMark
 
GET /better
GET /betterGET /better
GET /betterMark
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptMark
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptMark
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(Mark
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the RubyistMark
 
RubyMotion
RubyMotionRubyMotion
RubyMotionMark
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiMark
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the RubyistMark
 
Testing Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineTesting Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineMark
 
DRb and Rinda
DRb and RindaDRb and Rinda
DRb and RindaMark
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Mark
 

More from Mark (19)

Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web Apps
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the Rubyist
 
Mangling Ruby with TracePoint
Mangling Ruby with TracePointMangling Ruby with TracePoint
Mangling Ruby with TracePoint
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTest
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTest
 
GET /better
GET /betterGET /better
GET /better
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScript
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
 
RubyMotion
RubyMotionRubyMotion
RubyMotion
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and Chai
 
CoffeeScript for the Rubyist
CoffeeScript for the RubyistCoffeeScript for the Rubyist
CoffeeScript for the Rubyist
 
Testing Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with JasmineTesting Rich Client Side Apps with Jasmine
Testing Rich Client Side Apps with Jasmine
 
DRb and Rinda
DRb and RindaDRb and Rinda
DRb and Rinda
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010Distributed Programming with Ruby/Rubyconf 2010
Distributed Programming with Ruby/Rubyconf 2010
 

Recently uploaded

Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - AvrilIvanti
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneUiPathCommunity
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 

Recently uploaded (20)

Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - Avril
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyone
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 

Building an API in Rails without Realizing It

  • 5. http://www.metacasts.tv CONFOO2013 Monday, February 25, 13
  • 8. e b APIs Rails W Monday, February 25, 13
  • 9. you’re probably doing it wrong Monday, February 25, 13
  • 11. most APIs are an after thought Monday, February 25, 13
  • 12. we can prevent that! Monday, February 25, 13
  • 13. 3 simple rules for building an API Monday, February 25, 13
  • 14. 1. consume your own API Monday, February 25, 13
  • 15. 2. document your API Monday, February 25, 13
  • 16. 3. version your API Monday, February 25, 13
  • 17. building the API Monday, February 25, 13
  • 19. Service Oriented Architecture Monday, February 25, 13
  • 21. SOA Pros • Scales Easily Monday, February 25, 13
  • 22. SOA Pros • Scales Easily • Separate Concerns/Very Clean Monday, February 25, 13
  • 23. SOA Pros • Scales Easily • Separate Concerns/Very Clean • Can be easier to maintain Monday, February 25, 13
  • 24. SOA Pros • Scales Easily • Separate Concerns/Very Clean • Can be easier to maintain • Solid Architecture Monday, February 25, 13
  • 25. SOA Pros • Scales Easily • Separate Concerns/Very Clean • Can be easier to maintain • Solid Architecture • Easier to refactor/rebuild Monday, February 25, 13
  • 27. SOA Cons • Can be more difficult to maintain Monday, February 25, 13
  • 28. SOA Cons • Can be more difficult to maintain • More complex deploys Monday, February 25, 13
  • 29. SOA Cons • Can be more difficult to maintain • More complex deploys • Managing several applications Monday, February 25, 13
  • 30. SOA Cons • Can be more difficult to maintain • More complex deploys • Managing several applications • Potential for ‘out-of-sync’ apps Monday, February 25, 13
  • 31. SOA Cons • Can be more difficult to maintain • More complex deploys • Managing several applications • Potential for ‘out-of-sync’ apps • More difficult to test integration Monday, February 25, 13
  • 32. API Client Monday, February 25, 13
  • 33. Client API Client Monday, February 25, 13
  • 34. Client API Client Client Monday, February 25, 13
  • 35. Client Service 1 Service 2 Client Service 3 Client Monday, February 25, 13
  • 36. a quick detour Monday, February 25, 13
  • 37. Rails encourages poor API design! Monday, February 25, 13
  • 39.    #  POST  /todos    #  POST  /todos.json    def  create class  TodosController  <  ApplicationController        @todo  =  Todo.new(params[:todo])    #  GET  /todos      #  GET  /todos.json        respond_to  do  |format|    def  index            if  @todo.save        @todos  =  Todo.all                format.html  {  redirect_to  @todo,  notice:  'Todo  was  successfully  created.'  }                  format.json  {  render  json:  @todo,  status:  :created,  location:  @todo  }        respond_to  do  |format|            else            format.html  #  index.html.erb                format.html  {  render  action:  "new"  }            format.json  {  render  json:  @todos  }                format.json  {  render  json:  @todo.errors,  status:  :unprocessable_entity  }        end            end    end        end      end    #  GET  /todos/1      #  GET  /todos/1.json    #  PUT  /todos/1    def  show    #  PUT  /todos/1.json        @todo  =  Todo.find(params[:id])    def  update          @todo  =  Todo.find(params[:id])        respond_to  do  |format|              format.html  #  show.html.erb        respond_to  do  |format|            format.json  {  render  json:  @todo  }            if  @todo.update_attributes(params[:todo])        end                format.html  {  redirect_to  @todo,  notice:  'Todo  was  successfully  updated.'  }    end                format.json  {  head  :no_content  }              else    #  GET  /todos/new                format.html  {  render  action:  "edit"  }    #  GET  /todos/new.json                format.json  {  render  json:  @todo.errors,  status:  :unprocessable_entity  }    def  new            end        @todo  =  Todo.new        end      end        respond_to  do  |format|              format.html  #  new.html.erb    #  DELETE  /todos/1            format.json  {  render  json:  @todo  }    #  DELETE  /todos/1.json        end    def  destroy    end        @todo  =  Todo.find(params[:id])          @todo.destroy    #  GET  /todos/1/edit      def  edit        respond_to  do  |format|        @todo  =  Todo.find(params[:id])            format.html  {  redirect_to  todos_url  }    end            format.json  {  head  :no_content  }        end    end end Monday, February 25, 13
  • 42. class  TodosController  <  ApplicationController      def  index        @todos  =  Todo.all    end      def  show        @todo  =  Todo.find(params[:id])    end      def  new        @todo  =  Todo.new    end      def  edit        @todo  =  Todo.find(params[:id])    end      def  create        @todo  =  Todo.new(params[:todo])        if  @todo.save            redirect_to  @todo,  notice:  'Todo  was  successfully  created.'        else            render  action:  "new"        end    end      def  update        @todo  =  Todo.find(params[:id])          if  @todo.update_attributes(params[:todo])            redirect_to  @todo,  notice:  'Todo  was  successfully  updated.'        else            render  action:  "edit"        end    end      def  destroy        @todo  =  Todo.find(params[:id])        @todo.destroy        redirect_to  todos_path,  notice:  'Todo  was  successfully  destroyed.'    end end Monday, February 25, 13
  • 43. class  TodosController  <  ApplicationController    inherit_resources end Monday, February 25, 13
  • 44. Inherited Resources https://github.com/josevalim/inherited_resources Monday, February 25, 13
  • 46. class  Api::V1::TodosController  <  ApplicationController    respond_to  :json      before_filter  do        request.format  =  :json    end      def  index        @todos  =  Todo.all        respond_with  @todos    end      def  show        @todo  =  Todo.find(params[:id])        respond_with  @todo    end      def  create        @todo  =  Todo.new(params[:todo])        if  @todo.save            respond_with  @todo        else            render  json:  @todo.errors,  status:  :unprocessable_entity        end    end      def  update        @todo  =  Todo.find(params[:id])          if  @todo.update_attributes(params[:todo])            respond_with  @todo        else            render  json:  @todo.errors,  status:  :unprocessable_entity        end    end      def  destroy        @todo  =  Todo.find(params[:id])        @todo.destroy        head  :no_content    end end Monday, February 25, 13
  • 47. version your API! Api::V1::TodosController /api/v1/todos Monday, February 25, 13
  • 48. i prefer URL versioning Monday, February 25, 13
  • 49. others prefer header versioning Monday, February 25, 13
  • 50. just pick one and stick with it! Monday, February 25, 13
  • 52. SOA Review • We’ve cleaned up our code Monday, February 25, 13
  • 53. SOA Review • We’ve cleaned up our code • We know the API Works Monday, February 25, 13
  • 54. SOA Review • We’ve cleaned up our code • We know the API Works • We’re now in a good place to scale Monday, February 25, 13
  • 55. consuming the API Monday, February 25, 13
  • 56. don’t use Rails views Monday, February 25, 13
  • 59. Cross-origin Resource Sharing Monday, February 25, 13
  • 60. rack-cors https://github.com/cyu/rack-cors Monday, February 25, 13
  • 61. module  YourApp    class  Application  <  Rails::Application      #  ...      config.middleware.use  Rack::Cors  do        allow  do            origins  '*'            resource  '*',  headers:  :any,                                          methods:  [:get,  :post,  :put,  :delete,  :options]        end    end     end Monday, February 25, 13
  • 63. JavaScript Pros • Scales Easily/Pushes processing to client side Monday, February 25, 13
  • 64. JavaScript Pros • Scales Easily/Pushes processing to client side • Separate Concerns/Very Clean Monday, February 25, 13
  • 65. JavaScript Pros • Scales Easily/Pushes processing to client side • Separate Concerns/Very Clean • Can be easier to maintain Monday, February 25, 13
  • 66. JavaScript Pros • Scales Easily/Pushes processing to client side • Separate Concerns/Very Clean • Can be easier to maintain • “Responsive/Native” feel for clients Monday, February 25, 13
  • 67. JavaScript Pros • Scales Easily/Pushes processing to client side • Separate Concerns/Very Clean • Can be easier to maintain • “Responsive/Native” feel for clients • Easily consumes your API Monday, February 25, 13
  • 69. JavaScript Cons • Can be more difficult to maintain Monday, February 25, 13
  • 70. JavaScript Cons • Can be more difficult to maintain • Multiple languages (backend/front-end) Monday, February 25, 13
  • 71. JavaScript Cons • Can be more difficult to maintain • Multiple languages (backend/front-end) • Difficult to test integration Monday, February 25, 13
  • 72. JavaScript Cons • Can be more difficult to maintain • Multiple languages (backend/front-end) • Difficult to test integration • JavaScript Monday, February 25, 13
  • 73. JavaScript Cons • Can be more difficult to maintain • Multiple languages (backend/front-end) • Difficult to test integration • JavaScript • Paradigm shift in architecture Monday, February 25, 13
  • 74. JavaScript Cons • Can be more difficult to maintain • Accessibility issues • Multiple languages (backend/front-end) • Difficult to test integration • JavaScript • Paradigm shift in architecture Monday, February 25, 13
  • 75. JavaScript Cons • Can be more difficult to maintain • Accessibility issues • Multiple languages (backend/front-end) • SEO concerns • Difficult to test integration • JavaScript • Paradigm shift in architecture Monday, February 25, 13
  • 76. JavaScript Cons • Can be more difficult to maintain • Accessibility issues • Multiple languages (backend/front-end) • SEO concerns • Difficult to test integration • !!Internet Explorer!! • JavaScript • Paradigm shift in architecture Monday, February 25, 13
  • 77. pick a framework Monday, February 25, 13
  • 78. don’t just use jQuery Monday, February 25, 13
  • 79. the big three Monday, February 25, 13
  • 80. Backbone.js http://backbonejs.org/ Monday, February 25, 13
  • 81. ember http://emberjs.com/ Monday, February 25, 13
  • 82. Angular.js http://angularjs.org/ Monday, February 25, 13
  • 83. i can’t use JavaScript Monday, February 25, 13
  • 86. build your own API library (and open source it!) Monday, February 25, 13
  • 88. class  TodosController  <  ApplicationController      def  index        @todos  =  ApiLib::Todo.all    end      def  show        @todo  =  ApiLib::Todo.find(params[:id])    end      def  new        @todo  =  ApiLib::Todo.new    end      def  edit        @todo  =  ApiLib::Todo.find(params[:id])    end      def  create        @todo  =  ApiLib::Todo.new(params[:todo])        if  @todo.save            redirect_to  @todo,  notice:  'Todo  was  successfully  created.'        else            render  action:  "new"        end    end      def  update        @todo  =  ApiLib::Todo.find(params[:id])          if  @todo.update_attributes(params[:todo])            redirect_to  @todo,  notice:  'Todo  was  successfully  updated.'        else            render  action:  "edit"        end    end      def  destroy        @todo  =  ApiLib::Todo.find(params[:id])        @todo.destroy        redirect_to  todos_path,  notice:  'Todo  was  successfully  destroyed.'    end end Monday, February 25, 13
  • 89. hey! there is duplicate* code now Monday, February 25, 13
  • 90. is there? or did we just move it around? Monday, February 25, 13
  • 92. we now have a reference implementation Monday, February 25, 13
  • 93. make sure to cache!! Monday, February 25, 13
  • 95. Please don’t do this! Monday, February 25, 13
  • 97. Don’t use this hack! Monday, February 25, 13
  • 98. I probably shouldn’t even show you it. Monday, February 25, 13
  • 99. Ok, I’ll show you, but don’t tell people where you heard it. Monday, February 25, 13
  • 101. class  TodosController  <  ApplicationController      def  index        res  =  Api::V1::TodosController.action(:index).call(env)        @todos  =  JSON.parse(res[2].body).map  do  |data|            OpenStruct.new(data)        end    end   end Monday, February 25, 13
  • 102. projects worth noting Monday, February 25, 13
  • 109. Final Thoughts • Consume your API Monday, February 25, 13
  • 110. Final Thoughts • Consume your API • Version your API Monday, February 25, 13
  • 111. Final Thoughts • Consume your API • Version your API • Document your API Monday, February 25, 13
  • 112. Final Thoughts • Consume your API • Version your API • Document your API • Did I mention consume your own API? Monday, February 25, 13
  • 113. Thank You http://www.metacasts.tv CONFOO2013 @markbates Monday, February 25, 13