【Kong】API 操作簡(jiǎn)解

1. Upstreams

  • 創(chuàng)建
curl -X POST http://127.0.0.1:8001/upstreams --data "name=exampleUpstream"
  • 查詢
curl -i -X GET  --url http://127.0.0.1:8001/upstreams/exampleUpstream
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/upstreams/exampleUpstream --data "tags[]=tag1" --data "tags[]=tag2"
  • 刪除
curl -i -X DELETE --url http://127.0.0.1:8001/upstreams/exampleUpstream
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/upstreams?size=10

2. Target

  • 創(chuàng)建
curl -X POST http://127.0.0.1:8001/upstreams/exampleUpstream/targets --data "target=www.baidu.com:80" --data "weight=100"
  • 查詢
curl -i -X GET  --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets/www.baidu.com:80
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets/www.baidu.com:80 --data "tags[]=tag1" --data "tags[]=tag2"
  • 刪除
curl -i -X DELETE --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets/www.baidu.com:80
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets

3. Service

  • 創(chuàng)建
curl -i -X POST --url http://127.0.0.1:8001/services --data 'name=example' --data 'url=http://www.baidu.com'
  • 查詢
curl -i -X GET  --url http://127.0.0.1:8001/services/example
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/services/example --data 'retries=10' --data 'connect_timeout=80000'
  • 刪除
curl -i -X DELETE --url http://127.0.0.1:8001/services/example
  • ALL
curl -i -X GET --url http://127.0.0.1:8001/services?size=10

4.Routes

  • 創(chuàng)建
curl -i -X POST --url http://127.0.0.1:8001/services/example/routes --data 'name=ft' --data 'hosts[]=baidu.com' --data 'paths[]=/first'
  • 查詢
curl -i -X GET  --url http://127.0.0.1:8001/services/example/routes/ft
  • 更新
curl -i -X PATCH --url http://127.0.0.1:8001/services/example/routes/ft --data 'request_buffering=false' --data "tags[]=tag1" --data "tags[]=tag2"
  • 刪除
curl -i -X DELETE  --url http://127.0.0.1:8001/services/example/routes/ft
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/routes?size=10

5.Consumers

  • 創(chuàng)建
curl -i -X POST --url http://127.0.0.1:8001/consumers --data "username=jack"
  • 查詢
curl -i -X GET  --url http://127.0.0.1:8001/consumers/jack
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/consumers/jack --data "tags[]=tag1" --data "tags[]=tag2"
  • 刪除
curl -i -X DELETE --url http://127.0.0.1:8001/consumers/jack
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/consumers?size=10

6. ACL

  • 創(chuàng)建
curl -i -X POST --url http://127.0.0.1:8001/services/example/plugins --data "name=acl" --data "config.allow=admin"
  • 非法
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic amFjazoxMjM0NTY=" --header 'Host: baidu.com'
{
  "message":"You cannot consume this service"
}
  • 授權(quán)
curl -i -X POST --url http://localhost:8001/consumers/jack/acls --data "group=admin"
  • 訪問(wèn)
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic amFjazoxMjM0NTY=" --header 'Host: baidu.com'

<!DOCTYPE html>
<!--STATUS OK-->
<html>
<head>
<meta http-equiv=content-type content=text/html;charset=utf-8>
<meta http-equiv=X-UA-Compatible content=IE=Edge>
<meta content=always name=referrer>
<link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css>
<title>百度一下催烘,你就知道</title>
......................
</html>
  • 刪除
curl -i -X DELETE http://localhost:8001/services/example/plugins/1541e339-7b8f-4a1e-8485-45b0a28b55a8

7. Basic-Auth

  • 創(chuàng)建
curl -i -X POST --url http://localhost:8001/services/example/plugins --data "name=basic-auth"
  • 授權(quán)
curl -i -X POST --url http://localhost:8001/consumers/jack/basic-auth --data "username=jack" --data "password=123456"
  • 非法
curl -i -X GET --url http://localhost:8000/first --header 'Host:baidu.com'
{
  "message":"Unauthorized"
}
  • 異常
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic xxxxx=" --header 'Host: baidu.com'
{
  "message":"Invalid authentication credentials"
}
  • 正常
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic amFjazoxMjM0NTY=" --header 'Host: baidu.com'
<!DOCTYPE html>
<!--STATUS OK-->
<html>
<head>
<meta http-equiv=content-type content=text/html;charset=utf-8>
<meta http-equiv=X-UA-Compatible content=IE=Edge>
<meta content=always name=referrer>
<link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css>
<title>百度一下沥阱,你就知道</title>
......................
</html>
  • 刪除
curl -i -X DELETE http://localhost:8001/services/example/plugins/3d9703d5-bafb-4374-931c-a03222e3aef6

8. Key-Auth

  • 創(chuàng)建
curl -X POST http://localhost:8001/services/example/plugins --data "name=key-auth" --data "config.key_names=apikey"
  • 授權(quán)
curl -i -X POST --url http://localhost:8001/consumers/jack/key-auth --data 'key=123'
  • 非法
curl http://localhost:8000/first --header 'Host:baidu.com'
{
  "message":"No API key found in request"
}
  • 異常
curl http://localhost:8000/first?apikey=1231 --header 'Host:baidu.com'
{
  "message":"Invalid authentication credentials"
}
  • 正常
curl http://localhost:8000/first?apikey=123 --header 'Host:baidu.com'
<!DOCTYPE html>
<!--STATUS OK-->
<html>
<head>
<meta http-equiv=content-type content=text/html;charset=utf-8>
<meta http-equiv=X-UA-Compatible content=IE=Edge>
<meta content=always name=referrer>
<link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css>
<title>百度一下,你就知道</title>
......................
</html>
  • 刪除
curl -i -X DELETE http://localhost:8001/services/example/plugins/2ea0a367-e17e-4e8e-9b8f-8e8b9bf49681

9. IP-Restriction

  • 創(chuàng)建
curl -X POST http://localhost:8001/services/example/plugins --data "name=ip-restriction" --data "config.deny=118.123.78.69"
  • 訪問(wèn)
curl -i -X GET  --url http://localhost:8000/first --header 'Host: baidu.com'
{
  "message":"Your IP address is not allowed"
}
  • 取消
curl -i -X PATCH http://localhost:8001/services/example/plugins/08fe31e8-e961-4703-9d29-a877eed7c5c1 --data "config.deny=" --data "config.allow=118.123.78.69"
  • 刪除
curl -i -X DELETE http://localhost:8001/services/example/plugins/08fe31e8-e961-4703-9d29-a877eed7c5c1

10. Rate-Limiting

  • 創(chuàng)建
curl -X POST http://localhost:8001/services/example/plugins --data "name=rate-limiting" --data "config.second=2" --data "config.policy=local"
  • 訪問(wèn)
curl -i -X GET  --url http://localhost:8000/first --header 'Host: baidu.com'
{
  "message":"API rate limit exceeded"
}
  • 刪除
curl -i -X DELETE http://localhost:8001/services/example/plugins/9172ccc6-9734-4567-a442-04b03c5d7989

11. Request-Termination

  • 創(chuàng)建
curl -X POST http://localhost:8001/services/example/plugins --data "name=request-termination"  --data "config.status_code=200" --data "config.message=Test !! "
  • 訪問(wèn)
curl -i -X GET  --url http://localhost:8000/first --header 'Host: baidu.com'
{"message":"Test ll"}
  • 刪除
curl -i -X DELETE http://localhost:8001/services/example/plugins/cbf087f5-aa50-418d-a8a2-325ebb6c9109
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末伊群,一起剝皮案震驚了整個(gè)濱河市考杉,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌舰始,老刑警劉巖崇棠,帶你破解...
    沈念sama閱讀 218,204評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異丸卷,居然都是意外死亡枕稀,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)萎坷,“玉大人凹联,你說(shuō)我怎么就攤上這事《叩担” “怎么了蔽挠?”我有些...
    開封第一講書人閱讀 164,548評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)瓜浸。 經(jīng)常有香客問(wèn)我澳淑,道長(zhǎng),這世上最難降的妖魔是什么插佛? 我笑而不...
    開封第一講書人閱讀 58,657評(píng)論 1 293
  • 正文 為了忘掉前任杠巡,我火速辦了婚禮,結(jié)果婚禮上朗涩,老公的妹妹穿的比我還像新娘忽孽。我一直安慰自己,他們只是感情好谢床,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,689評(píng)論 6 392
  • 文/花漫 我一把揭開白布兄一。 她就那樣靜靜地躺著,像睡著了一般识腿。 火紅的嫁衣襯著肌膚如雪出革。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,554評(píng)論 1 305
  • 那天渡讼,我揣著相機(jī)與錄音骂束,去河邊找鬼。 笑死成箫,一個(gè)胖子當(dāng)著我的面吹牛展箱,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蹬昌,決...
    沈念sama閱讀 40,302評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼混驰,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了皂贩?” 一聲冷哼從身側(cè)響起栖榨,我...
    開封第一講書人閱讀 39,216評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎明刷,沒想到半個(gè)月后婴栽,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,661評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡辈末,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,851評(píng)論 3 336
  • 正文 我和宋清朗相戀三年愚争,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了映皆。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,977評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡准脂,死狀恐怖劫扒,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情狸膏,我是刑警寧澤沟饥,帶...
    沈念sama閱讀 35,697評(píng)論 5 347
  • 正文 年R本政府宣布,位于F島的核電站湾戳,受9級(jí)特大地震影響贤旷,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜砾脑,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,306評(píng)論 3 330
  • 文/蒙蒙 一幼驶、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧韧衣,春花似錦盅藻、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,898評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至硕噩,卻和暖如春假残,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背炉擅。 一陣腳步聲響...
    開封第一講書人閱讀 33,019評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工辉懒, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人谍失。 一個(gè)月前我還...
    沈念sama閱讀 48,138評(píng)論 3 370
  • 正文 我出身青樓眶俩,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親快鱼。 傳聞我的和親對(duì)象是個(gè)殘疾皇子仿便,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,927評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容