🥸
curlコマンドのメモ
準備
echo "const express=require('express');
const app=express();
app.use(express.json());
app.get('/',(req,res)=>{
res.json({\"name\":\"wasabina67\",\"age\":\"100\"});
});
app.post('/',(req,res)=>{
console.log(req.body);
res.json({\"status\":\"success\"});
});
app.listen(3000,()=>console.log('Server running → http://localhost:3000'));" > server.js && \
npm i express && \
node server.js
よく使うオプション
-
-X
- HTTPメソッドを指定
-
-H
- HTTPヘッダーを指定
-
-d
- POSTするデータを指定
-
-i
- レスポンスヘッダーを表示
-
-v
- 詳細な情報(verbose)を表示
-
-o
- 結果をファイルに保存
GET
curl http://localhost:3000/
curl -H "Authorization: Bearer MY_TOKEN" http://localhost:3000/
curl -i http://localhost:3000/
POST
curl -X POST -H "Content-Type: application/json" -d '{"name":"wasabina67", "age":"31"}' http://localhost:3000/
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name":"wasabina67", "age":"31"}' \
http://localhost:3000/
-
-d
を利用するのは、POSTなので、-X
の指定は省略できる
Discussion