《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和秘钥

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




Windows Azure Platform 系列文章目录

 

  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

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




Windows Azure Platform 系列文章目录  

 

  使用CosmosDB REST API主要的事项:

  1.Auth认证

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

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

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




Windows Azure Platform 系列文章目录

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

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




Windows Azure Platform 系列文章目录

 

  2.Partition Key

  如果我们的Collection里面设置了Partition Key,对CosmosDB的操作需要有变化

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

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




Windows Azure Platform 系列文章目录

 

  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

 

相关文章:

  • 2021-07-31
  • 2022-02-28
  • 2021-06-29
  • 2021-12-14
  • 2021-05-15
  • 2021-05-23
  • 2022-01-11
  • 2021-10-13
猜你喜欢
  • 2021-11-13
  • 2021-10-28
  • 2021-05-17
  • 2022-02-13
  • 2022-03-06
  • 2021-12-28
  • 2021-11-15
相关资源
相似解决方案