SlideShare a Scribd company logo
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

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfChristopherTHyatt
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationZilliz
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 

Recently uploaded (20)

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 

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