簡單的測試 reset api 可以像下面這樣
curl http://localhost:8080/path/to/api/
curl命令默認是發送GET請求的,可以通過選項 -X來設置
curl -X GET http://localhost:8080/path/to/api/
curl -X PUT http://localhost:8080/path/to/api/
curl -X POST http://localhost:8080/path/to/api/
curl -X DELETE http://localhost:8080/path/to/api/
curl命令發送請求同時帶上數據,可以使用-d選項。
curl -X PUT -d@testdata.txt --header "Content-Type: application/json" http://localhost:8080/path/to/api/
不過-d選項會把內容中的換行移除。我還可以使用–data-binary 選項代替
curl -X PUT --data-binary @testdata.txt --header "Content-Type: text/plain" http://localhost:8080/path/to/api/
curl發送請求帶上用戶認證,也就是帶上用戶名密碼
curl --digest --user username:password http://localhost:8080/a/path/to/api/
curl -X PUT --digest --user john:2LlAB3K9B0PF --data-binary @project-desc.txt --header "Content-Type: application/json; charset=UTF-8" http://localhost:8080/a/projects/myproject/description
我們也可以吧用戶名密碼存到 .netrc文件中 (Windows系統是這個_netrc文件):
curl --digest -n http://localhost:8080/a/path/to/api/
curl -v -n --digest -X DELETE http://localhost:8080/a/path/to/api/