超媒体API
2019獨角獸企業重金招聘Python工程師標準>>>
curl https://api.github.com
超媒體API的目標之一,是讓客戶端在不重新便編寫代碼的前提下動態調整所用的端點。
使用jq可以在命令行中解析JSON
jq安裝方式
os系統可以用brew
brew install jq示例用法:
curl https://api.github.com | jq '.current_user_url'?
curl -s https://api.github.com/users/xrd/repos | jq '.[0].owner.id'
cURL的調試開關
使用? -i 開關打印請求頭部
curl -i https://apis.github.com
使用 -v開關請求和響應首部
curl -v https://apis.github.com
使用條件請求規避頻率限制
If-Modified-Since (對應時間) 和 If-None-Match(對應ETag)
curl -i https://api.github.com/repos/twbs/bootstrap -H "If-Modified-Since: Sun, 11 Aug 2013 19:48.59 GMT"
curl -i https://api.github.com/repos/twbs/bootstrap -H 'If-None-Match: "dd05e06d7110bed317b80f8dc2cabf6d"'
JSON-P例子
<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title> </head><body><script>function myCallBack(payload) {console.log('payload', payload);}</script><script src="https://api.github.com/?callback=myCallBack"></script></body></html>?
指定響應的內容格式
URL='https://api.github.com/repos/rails/rails/issues/11819' curl -s $URL | jq '.body' curl -s $URL | jq '.body_html' curl -s $URL H "Accept: application/vnd.github.html+json" | jq '.body_html'?
轉載于:https://my.oschina.net/lilugirl2005/blog/3044771
總結
- 上一篇: 学习oop知识之OOP的封装
- 下一篇: LeetCode每日一题: 最后一个单