10. HTTP Cliente
HTML
API - JSON
RESTfull
Aplicação Servidor Externo
JSON XML
RESTfull WS - SOAP
app-servidor
11.
12. class XptoController < ApplicationController
def show
@xpto = Xpto.find params[:id]
end
end
resource :xpto, :only => [:show]
13. class XptoController < ApplicationController
def show
@xpto = Xpto.find params[:id]
respond_to do |format|
format.html
format.json{ render :json => @xpto }
end
end
end
14. @xpto.to_json
{
"id": 1,
"text": "Foo Bar",
"created_at": "2012-04-12T01:37:27Z",
class XptoController < ApplicationController
def show"updated_at": "2012-04-12T01:37:27Z"
}
@xpto = Xpto.find params[:id]
respond_to do |format|
format.html
format.json{ render :json => @xpto }
end
end
end
15. class XptoController < ApplicationController
def show
@xpto = Xpto.find params[:id]
respond_to do |format|
format.html
format.json{
render :json => @xpto.to_json(:include =>
[:children])
}
end
end
end
16. class XptoController < ApplicationController
def show
@xpto.to_json
@xpto = Xpto.find params[:id]
JSON::ParserError: 756: unexpected token at
respond_to do |format|
format.html
format.json{
render :json => @xpto.to_json(:include =>
[:children])
}
end
end
end
18. class XptoController < ApplicationController
def show
@xpto = Xpto.find params[:id]
respond_to do |format|
format.html
format.json{
render :json => @xpto.to_json(:include =>
[:children])
}
end
end
end
19. class XptoController < ApplicationController
def show
@xpto = Xpto.find params[:id]
respond_to do |format|
format.html
format.json{
render :json => @xpto.as_json(:include =>
[:children])
}
end
end
end
20. class XptoController < ApplicationController
def show
@xpto = Xpto.find params[:id]
respond_to do |format|
format.html
format.json{
render :json => @xpto
}
end
end
end
21. class Xpto
def as_json(options={})
super(options.merge(:include => [:children]))
end
end
22. class YptoController < ApplicationController
respond_to :html, :json
def show
@xpto = Xpto.find params[:id]
respond_with @xpto
end
end