Azure CosmosDB使用Postman訪問CosmosDB REST API

來源:博客園
作者:LeiZhang
時間:2020-09-14
2473
今天研究了一下如何使用Postman訪問Azure CosmosDB。

今天研究了一下如何使用Postman訪問Azure CosmosDB。

CosmosDB API接口,可以參考:https://docs.microsoft.com/en-us/rest/api/cosmos-db/get-a-document

1.首先,我們登錄https://portal.azure.cn,獲得url和秘鑰

ia_6400000003.png

2.安裝Postman,導(dǎo)入下面兩個文件:

(1)環(huán)境變量

https://github.com/leizhang1984/Postman/blob/master/CosmosDB/DocumentDBOptions.postman_environment.json

修改DocumentDBMasterKey的Value,修改為上圖的Primary Key

修改DocumentDBHost的Value,修改為CosmosDB的DNS Name

(2)導(dǎo)入Collection

https://github.com/leizhang1984/Postman/blob/master/CosmosDB/DocumentDB%20copy.postman_collection.json

3.打開Postman,選擇DocumentDBOptions

ia_6400000004.png

使用CosmosDB REST API主要的事項:

1.Auth認(rèn)證

無論訪問CosmosDB哪個REST API,Header必須添加該屬性

我已經(jīng)在Pre-request Script里面構(gòu)造好了

ia_6400000005.png

然后在Header里面,增加了Authorization信息

ia_6400000006.png

2.Partition Key

如果我們的Collection里面設(shè)置了Partition Key,對CosmosDB的操作需要有變化

比如方法:Get a Document里面,需要在Headers里面增加:x-ms-documentdb-partitionkey,該值為Partition Key Value

ia_6400000007.png

Collection可以訪問的API有:

(1)List Databases

(2)Get All Collections

修改DNS Name:https://{{DocumentDBHost}}/dbs/[這里修改為DatabaseName]/colls

(3)Get All Document

(4)Query Collection MemberInfo

(5)Get a Document

原文鏈接:點擊前往 >
版權(quán)說明:本文內(nèi)容來自于博客園,本站不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。文章內(nèi)容系作者個人觀點,不代表快出海對觀點贊同或支持。如有侵權(quán),請聯(lián)系管理員(zzx@kchuhai.com)刪除!
個人VIP
小程序
快出海小程序
公眾號
快出海公眾號
商務(wù)合作
商務(wù)合作
投稿采訪
投稿采訪
出海管家
出海管家