1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

curlコマンドでHTTPメソッド(GET/POST/PUT/DELETE)を実行する方法

Posted at

curl を使って各HTTPメソッド(GET、POST、PUT、DELETE)を実行する方法は以下の通り。

GET

GETリクエストはURLにデータを送信して、リソースを取得する。

zsh
% curl -X GET "https://api.example.com/resource"

POST

POSTリクエストはデータをサーバーに送信して、新しいリソースを作成する。データは通常、リクエストボディに含まれる。

zsh
% curl -X POST "https://api.example.com/resource" -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json"

PUT

PUTリクエストは既存のリソースを更新する。データはPOSTと同様にリクエストボディに含まれる。

zsh
% curl -X PUT "https://api.example.com/resource/1" -d '{"key1":"newvalue1", "key2":"newvalue2"}' -H "Content-Type: application/json"

DELETE

DELETEリクエストは特定のリソースを削除する。

zsh
% curl -X DELETE "https://api.example.com/resource/1"
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?