超媒体API
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
curl https://api.github.com
超媒體API的目標(biāo)之一,是讓客戶端在不重新便編寫代碼的前提下動(dòng)態(tài)調(diào)整所用的端點(diǎn)。
使用jq可以在命令行中解析JSON
jq安裝方式
os系統(tǒng)可以用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的調(diào)試開關(guān)
使用? -i 開關(guān)打印請(qǐng)求頭部
curl -i https://apis.github.com
使用 -v開關(guān)請(qǐng)求和響應(yīng)首部
curl -v https://apis.github.com
使用條件請(qǐng)求規(guī)避頻率限制
If-Modified-Since (對(duì)應(yīng)時(shí)間) 和 If-None-Match(對(duì)應(yīng)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>?
指定響應(yīng)的內(nèi)容格式
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'?
轉(zhuǎn)載于:https://my.oschina.net/lilugirl2005/blog/3044771
總結(jié)
- 上一篇: 学习oop知识之OOP的封装
- 下一篇: LeetCode每日一题: 最后一个单