RESTful API
- RESTful: 경로와 메소드 만으로 어떤 행위를 하는건지 알 수 있는 것
- RESTful API: RESTful 규칙으로 만들어진 api
- controller: 경로에 들어왔을 때 프론트 단에 적합한 상품을 뿌려줘야하는데 그 작업을 하는게 controller
Rails.application.routes.draw db
get '/items' => 'items#index'
post 'items' => 'items#create'
resources :items, shallow: true, except: [:index, :show] do
resources :options
end
end
rails routes|grep items
Rails.application.routes.draw db
resources :items, shallow: true, except: [:index, :show] do
resources :options
collection do
get :hello
end
member do
get :hello
end
end
end
API로 로그인 하기
brew install redis
redis-server
redis-cli
keys *
- postman으로 header에 csrf와 토큰을 넣어서 요청을 보냄
Serializer
rails g api items
def each_serialize
end
def serialize
end
- 디버깅을 하기 쉽게 만들어진 것: byebug
def create
byebug
end
Item.create(params.permit(:name, :price))
Item.create(params.require(:item).permit(:name, :price))