Upgrade to Pro — share decks privately, control downloads, hide ads and more …

意図せぬレスポンスを防ぐAPI設計2つのコツ / Startup Rails #6

taogawa
July 18, 2017

意図せぬレスポンスを防ぐAPI設計2つのコツ / Startup Rails #6

2017/7/18「第6回スタートアップRails勉強会」での発表スライドです

taogawa

July 18, 2017
Tweet

More Decks by taogawa

Other Decks in Programming

Transcript

  1. render json: @user.as_json # => response # { # "id":

    1, # "first_name": "hike", # "last_name": "kitch", # ... # "password_digest": "xxxxxxxxx" # !!!!! # }
  2. before render json: @user.as_json # => response # { #

    "id": 1, # "first_name": "hike", # "last_name": "kitch", # ... # } • as_json͸σϑΥϧτͰશͯͷ߲໨Λฦ͢ͷͰ ਏ͍ɾɾɾ
  3. after class UserSerializer < ActiveModel::Serializer attributes :id, :full_name def full_name

    "#{object.first_name} #{object.last_name}" end end # => response # { # "id": 1, # "full_name": "hike kitch" # }
  4. after # /kitchens/:id class KitchensController < ApplicationController def show end

    end # /self/kitchens/:id class Self::KitchensController < ApplicationController def show end end