LoginSignup
0
0

More than 1 year has passed since last update.

curlコマンドにオプションつけて色々設定

Last updated at Posted at 2022-01-29

##環境

  • Ruby 2.7.4
  • Rails 6.1.4.4
  • curl 7.77.0

##curl(読み方:カール)
curlコマンドとは、データ転送をさまざまなプロトコルで行うことができるコマンド。
HTTPのGET、POST、PUT、DELETEの他にもHTTPS、FTPでも対応している。

※本記事ではデータの作成、更新、削除について記す。

###curlを使ったデータの作成(POST)
curl -X POST http://sanmple:3000/examplesでPOSTオプションが指定。

(コマンド例)
$ curl -X POST -d 'example[title]=hoge' http://sample:3000/examples

※「-d」とはdataを表しており、以上の場合POSTするデータを指定する。

###curlを使ったデータの更新(PUT)
curl -X PUT ...でPUTオプションが指定。

(コマンド例)
$ curl -X PUT -d 'example[title]=fuga' http://sample:3000/examples/1

###curlを使ったデータの削除(DELETE)
curl -X DELETE ...でDELETEオプションが指定。

(コマンド例)
$ curl -X DELETE http://sample:3000/examples/1

以上

0
0
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
0
0