curl https://api.github.com
超媒体API的目标之一,是让客户端在不重新便编写代码的前提下动态调整所用的端点。
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'
使用 -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"'
<!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'