./categories/server
CLI REST API 클라이언트 (cURL/HTTPie)
CLI에서 REST API 호출
cURL
sudo apt-get install curl
curl -i -X GET http://127.0.0.1:3000/api/users/id
curl -X POST http://127.0.0.1:3000/api/items
curl -X PUT -H "Content-Type: application/json" -d '{"message":"hello"}' http://127.0.0.1:3000/api/chat
curl -X GET --data-urlencode "id=1000&category=post" http://127.0.0.1:3000/api/data
옵션: -i 응답헤더, -v 전체, -X 메소드, -H 헤더, -d 본문
resty (cURL 래퍼)
curl -L https://github.com/micha/resty/raw/master/resty > resty
source resty
resty 127.0.0.1:3000/api
GET /users/id
PUT -H 'Content-Type: application/json' -d '{"message":"hello"}' /chat
HTTPie
sudo apt-get install httpie
http GET 127.0.0.1:3000/api/users/id
http -v PUT 127.0.0.1:3000/api/chat body='{"message":"hello"}'
http -v --form PUT 127.0.0.1:3000/api/users/id name='Name' photo@file.png
Vim REST Console
.rest 파일에 요청 작성 후 <C-j> 실행:
http://127.0.0.1:3000
GET /api/users/id
관련 링크: https://bakyeono.net/post/2016-05-02-rest-api-client-for-cli.html
./comments