On Github alicial / wwcode-api-talk
-------------- GET /coders -----------> client server <-------- <html>...</html> ------------ -------------- GET /coders -----------> client server (API) <---- {'coders':['Alice','Bob']} ------
#routes.rb resources :coders, :only => [:create, :show, :update, :delete] # POST /coders # GET /coders/:id # PUT /coders/:id # DELETE /coders/:id
# coders_controller.rb class CodersController < ApplicationController def show @coder = Coder.find(params[:id]) respond_to do |format| format.html format.json { render :json => @coder.as_json } end end end
#routes.rb namespace :api do namespace :v1 do get '/coders', :to => 'coders#index' get '/coders/:id', :to => 'coders#show' end namespace :v2 do get '/coders/:id', :to => 'coders#show' end end # GET /api/v1/coders # GET /api/v1/coders/:id # GET /api/v2/coders/:id # GET /api/v2/coders => 404
Pun not intended