25
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RailsのためのCurlコマンドの備忘録

Last updated at Posted at 2016-08-25

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'
25
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?