自分用。毎回調べているのでまとめておく
- GETリクエスト
curl https://api.example.com/resource
- POSTリクエスト
curl -X POST https://api.example.com/resource
- POSTリクエスト(JSONデータを送信)
curl -X POST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' https://api.example.com/resource
- PUTリクエスト
curl -X PUT https://api.example.com/resource/id
- PUTリクエスト(JSONデータを送信)
curl -X PUT -H "Content-Type: application/json" -d '{"key1":"new_value1", "key2":"new_value2"}' https://api.example.com/resource/id
- DELETEリクエスト
curl -X DELETE https://api.example.com/resource/id
- Basic認証
curl -u username:password https://api.example.com/resource
- Bearerトークン認証
curl -H "Authorization: Bearer <ACCESS_TOKEN>" https://api.example.com/resource
- カスタムヘッダーの追加
curl -H "Custom-Header: custom_value" https://api.example.com/resource
- 複数のヘッダーを追加
curl -H "Content-Type: application/json" -H "Custom-Header: custom_value" https://api.example.com/resource
- レスポンスヘッダーの表示
curl -I https://api.example.com/resource
- リダイレクトを追跡
curl -L https://api.example.com/resource
- タイムアウトの設定
curl --max-time 10 https://api.example.com/resource
- jsonファイルからリクエスト
curl -X POST -H "Content-Type: application/json" -d @jsonpath https://api.example.com/resource