Azure CosmosDB (14) 使用Postman访问CosmosDB REST API

  《Windows Azure Platform 系列文章目录

  今天研究了一下如何使用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,导入下面两个文件:

  (1)环境变量

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

  修改DocumentDBMasterKey的Value,修改为上图的Primary Key

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

  

  (2)导入Collection

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

  

  3.打开Postman,选择DocumentDBOptions

    

  使用CosmosDB REST API主要的事项:

  1.Auth认证

  无论访问CosmosDB哪个REST API,Header必须添加该属性

  我已经在Pre-request Script里面构造好了

  

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

  

  2.Partition Key

  如果我们的Collection里面设置了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

原文地址:https://www.cnblogs.com/threestone/p/11460134.html