Desenvolvendo APIs usando Rails - Guru SC 2012
Upcoming SlideShare
Loading in...5
×
 

Desenvolvendo APIs usando Rails - Guru SC 2012

on

  • 1,039 views

My talk at the GuruSC (Santa Catarina's ruby user group) 2012

My talk at the GuruSC (Santa Catarina's ruby user group) 2012

Statistics

Views

Total Views
1,039
Views on SlideShare
960
Embed Views
79

Actions

Likes
0
Downloads
4
Comments
0

3 Embeds 79

http://gurusc.heroku.com 68
http://coderwall.com 8
http://localhost 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Desenvolvendo APIs usando Rails - Guru SC 2012 Desenvolvendo APIs usando Rails - Guru SC 2012 Presentation Transcript

  • Construíndo APIs usando Rails Rafael Felix
  • Rafael quem?
  • Rafael quem?Rafael Felix Software Developer
  • Aplicação Servidor Externo
  • XMLAplicação Servidor Externo WS - SOAP
  • Aplicação Servidor Externo
  • Aplicação Servidor Externo app-servidor
  • Aplicação Servidor Externo JSON XML RESTfull WS - SOAP app-servidor
  • ClienteAplicação Servidor Externo JSON XML RESTfull WS - SOAP app-servidor
  • HTTP Cliente HTML API - JSON RESTfullAplicação Servidor Externo JSON XML RESTfull WS - SOAP app-servidor
  • class XptoController < ApplicationController def show @xpto = Xpto.find params[:id] endend resource :xpto, :only => [:show]
  • class XptoController < ApplicationController def show @xpto = Xpto.find params[:id] respond_to do |format| format.html format.json{ render :json => @xpto } end endend
  • @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 endend
  • 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 endend
  • 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 endend
  • E agora quem poderá nos defender?
  • 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 endend
  • 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 endend
  • class XptoController < ApplicationController def show @xpto = Xpto.find params[:id] respond_to do |format| format.html format.json{ render :json => @xpto } end endend
  • class Xpto def as_json(options={}) super(options.merge(:include => [:children])) endend
  • class YptoController < ApplicationController respond_to :html, :json def show @xpto = Xpto.find params[:id] respond_with @xpto endend
  • https://github.com/nesquena/rabl
  • app/views/xpto/show.json.rablobject @xptochild :children do attributes :id, :name, :descriptionend
  • app/views/ypto/show.json.rabl object @xpto child :owner do attributes :id, :name end
  • https://github.com/rails/jbuilder
  • app/views/xpto/show.json.jbuilderjson.(@xpto, :id, :text, :created_at, :updated_at)json.children @xpto.children, :id, :name, :description
  • app/views/ypto/show.json.jbuilderjson.(@xpto, :id, :text, :created_at, :updated_at)json.owner do |json| json.id @xpto.owner.id json.name @xpto.owner.name json.description @xpto.owner.descriptionend
  • class XptoController < ApplicationController respond_to :html, :json def show @xpto = Xpto.find params[:id] respond_with @xpto endend
  • Obrigado! @rs_felixfelix.rafael@gmail.com