Never forget to change application.rb like this.
application.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
end
Http RequestのAcceptを変更する
jsonを指定する場合
This is for json
curl -v -H "Accept: application/json" http://localhost:3000/users
xmlを指定する場合
This is for xml
curl -v -H "Accept: application/xml" http://localhost:3000/users
Response headerのみを見たい時
When we see Response header
curl -I http://localhost:3000/users
Http methodを指定する場合
When we wanna specify HTTP verb
DELETE
curl -X DELETE http://localhost:3000/users/1
curl -v -H "Accept: application/json" -X DELETE http://localhost:3000/users/12
POST
こういうHashをRailsに送信したい場合
When we want to send hash like this.
"user"=>{"name"=>"test1", "email"=>"test1@gmail.com"}
curl -X POST http://localhost:3000/users -d 'user[name]=test1&user[email]=test1@gmail.com'
curl -v -H "Accept: application/json" -X POST http://localhost:3000/users -d 'user[name]=test1&user[email]=test1@gmail.com'
PUT
curl -X PUT http://localhost:3000/users/10 -d 'user[name]=test333&user[email]=test1@gmail.com'