今天研究了一下如何使用Postman訪問Azure CosmosDB。
CosmosDB API接口,可以參考:https://docs.microsoft.com/en-us/rest/api/cosmos-db/get-a-document
1.首先,我們登錄https://portal.azure.cn,獲得url和秘鑰
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
使用CosmosDB REST API主要的事項:
1.Auth認(rèn)證
無論訪問CosmosDB哪個REST API,Header必須添加該屬性
我已經(jīng)在Pre-request Script里面構(gòu)造好了
然后在Header里面,增加了Authorization信息
2.Partition Key
如果我們的Collection里面設(shè)置了Partition Key,對CosmosDB的操作需要有變化
比如方法:Get a Document里面,需要在Headers里面增加:x-ms-documentdb-partitionkey,該值為Partition Key Value
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