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

Ff07ba188f0dccc30e7a90a5ebd1a386?s=47 taogawa
July 18, 2017

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

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

Ff07ba188f0dccc30e7a90a5ebd1a386?s=128

taogawa

July 18, 2017
Tweet

Transcript

  1. 7.

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

    1, # "first_name": "hike", # "last_name": "kitch", # ... # "password_digest": "xxxxxxxxx" # !!!!! # }
  2. 12.

    before render json: @user.as_json # => response # { #

    "id": 1, # "first_name": "hike", # "last_name": "kitch", # ... # } • as_json͸σϑΥϧτͰશͯͷ߲໨Λฦ͢ͷͰ ਏ͍ɾɾɾ
  3. 14.

    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. 19.

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

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