zoukankan      html  css  js  c++  java
  • 整理PostMan的基础用法2

    PUT更新集合

          https://api.getpostman.com/collections/{{collection_uid}}

       这个端点允许你通过Postman Collection v2格式来更新一个已存在的集合。

       成功更新好集合后,响应返回一个集合的name,id,和uid.

         需要API Key作为X-Api-Key请求头或apikey URL查询参数。

     注意:需要小心--尝试更新集合时,已有的集合会被请求体替代

     

     头文件HEADERS

      Content-Type: application/json

      X-Api-Key: {{postman_api_key}}

     请求体部分BODY

      {

         "collection": { "info": { "name": "sample collection 952",

          "description": "This is a smple collection", "_postman_id": "174dad7d-07e4-45fe-917d-13cf84e5581f", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" },

          "item": [ { "name": "This is a folder", "item": [ { "name": "sample POST Request",

         "request": { "url": "https://postman-echo.com/post", "method": "POST",

         "header": [ { "key": "Content-Type", "value": "application/json" } ] ,

         "body": { "mode": "raw", "raw": "{"data": "123"} },

          "description": "This is a smple POST Request" } } ] },

          { "name": "smaple GET Request", "request": { "url": "https://postman-echo/get",

           "method": "GET", "description": "This is a smple GET Request"

          } }   ]   } }

      示例请求:更新后的集合

       curl --location --request PUT "https://api.getpostman.com/collections/{{collection_uid}}"

          --header "Content-Type": application/json"

          --header "X-Api-Key": {{postman_api_key}}"

          --data "{ "collection": { "variables": [ ], "info": { "name": "sample collection",

           "_postman_id": "1d4daef5-2021-4581-ab84-bdfe5d5f5a55",

          "description": "This is just a smple collection.",

          "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"

          },

           "item":  [ { "name": "This is a folder", "description": "",

               "item": [ { "_postman_id": "c5e8d7ef-909d-4v57-wef2-8609wc501586",

               "name": "smple POST Request",

               "request": { "url": "echo.getpostman.com/post", "method": "POST",

              "header": [ { "key": "Content-Type", "value": "application/json",

               "description": "" } ],

               "body": { "mode": "raw", "raw": "{   \"data\": \"123\" } " } ,

               "description": "This is a smple POST Request" },

              "response": [ ] } ] },

               { "name": "This is a second folder", "description": "This is the second folder",

                 "item": [ ] } ,

               { "name": "smple GET Request", "request": { "url": "echo.getpostman.com/get",

               "method": "GET", "header": [ ], "body": { "mode": "formdata" , "formdata": [] },

               "description": "This is the second request" } ,

               "response": [ ] } ] } }"

     

     DEL删除集合

         https://api.getpostman.com/collections/{{collection_uid}}

        这个端点允许你来删除已有的集合。

        完成集合删除后,响应返回id,uid.

            需要API Key作为X-Api-Key请求头文件或apikey URL查询参数。

       头文件HEADERS

        X-Api-Key: {{postman_api_key}}

        请求栗子:

           已删除的集合:

         curl --location --request DELETE "https://api.getpostman.com/collections/{{collection_uid}}"

           --header "X-Api-Key: {{postman-api-key}}"

          --data ""

          响应栗子:

        200 - OK

            { "collection": { "id": "a14d5d5-afba-4a82-bf22-413febaaedaa2a",

                "uid": "5513-a1413113aaaedade-4132-aewefwffewfe13"

              }

           }

    环境变量

        GET 所有的环境变量: https://api.getpostman.com/environments

        /environments端点返回一个所有环境变量的集合。

        响应包括一个环境变量信息的数组内容有name,id,owner和uid.

          需要API Key作为X-Api-Key0请求头或apikey0 URL查询参数。

      

        头文件HEADERS

         X-Api-Key: {{postman_api_key}}

        请求实力:

         有效的响应:

             curl --location --request GET "https://api.getpostman.com/environments"

                  --header "X-Api-Key: {{postman_api_key}}"

         响应实力:

            200 - OK

           { "environments": [ { "id": "357668d2-84f1-2213-438b-11309592f81",

              "name": "Postman cloud API",

              "owner": "621342", "uid": "621342-357668d2-84f1-2213-438b-11309592f81"},

            { "id": "841d135fe-f4b1-9120-5f11-a73b17818d70",

               "name": "Postman Cloud API.template",

               "owner": "621245",

               "uid": "621245-841d135fe-f4b1-9120-5f11-a73b17818d70"} ] }

        GET 单一环境变量

           https://api.getpostman.com/environments//{environment_uid}}

         访问一个可以访问的环境变量的内容,使用uid.

              xu要API Key作为X-Api-Key请求头或apikey URL0查询参数。

     

     头文件HEADERS

     X-Api-Key: {{postman_api_key}}

     

    请求示例:

         curl --location -- request GET "https://api.getpostman.com/environments/{{environment_uid}}"

           --header "X-Api-Key: {{postman_api_key}}"

    响应示例:

        200 - OK

        { " environment": {

          "id": "81a1139b5-f5b2-8120-5f11-a7845b458890",

          "name": "Postman cloud API.template",

          "values": [ { "key": "postman_api_key", "value": "", "type": "text", "enabled": true, "hovered": false } ] } }

      

        POST 创建环境变量

        https://api.getpostman.com/environments

         以下是一个添加到遵循JSON格式的请求的样例体。

        {  "type": "object", "properties": { "environments": {"type": "object",

           "properties": { "name": { "type": "string", "maxLength": 254, "minLength": 1 },

           "value": {"type": "string"}, "enabled": {"type": "boolean" } },

           "required": ["key": "value"]

         }  }  },

           "required": ["name"] } },

          "required": ["environment"] }

     创建完成环境变量,API 返回环境变量的name和id.

      也可以指定工作空间的背景来创建一个环境变量,将workspace作为查询参数传递出去。

          xu要API Key作为X-Api-Key请求头或apikey URL查询参数。

     

     头文件HEADERS

       Content-Type: application/json

       X-Api-Key: {{postman_api_key}}

     请求体部分:

      { "environment": { "name": "smple environment name (required)",

        "values": [ "key": "variable_name_1", "value": "the value of the variable"},

                     {"key": "variable_name_2", "value": ""} ] } }

     示例请求:

         失败的响应

       url --location --request POST "https://api.getpostman.com/environments"

         --header "Content-Type: application/json"

        --header "X-Api-Key: {{postman_api_key}}"

        --data "{  } "

        示例响应

        400 -  bad请求

         { "error": { "name": "malformedRequestError",

              "message": "Missing required property: environment"

         } }

     PUT 更新环境变量

       https://api.getpostman.com/environments/{{environment_uid}}

      这个端点替代已存在的环境变量。

     

      以下是一个符合JSON格式的请求体:

     { "type": "object", "properties": { "environment": { "type": "object",

      "properties": { "name": { "type": "string", "maxLength": 254, "minLength": 1 },

      "values": { "type": "array", "maxItems": 100, "additionalItems": false,

      "items": { "type": "object", "properties": { "key" : {"type": "string", "maxLength":254, "minLength":1 }, 

      "value": { "type": "string", "maxLength": 254, "minLength":1 },

       "type": {"type": "string" },  "enabled": { "type": "boolean" } },

       "required": [ "key","value" ] } }

         } } },

      "required": [ "environment" ] }

          完成环境变量的更新,API返回环境变量的name和 id.

             xu要API Key作为X-Api-Key请求头或apikey URL查询参数。

      头文件HEADERS

        Content-Type: application/json

        X-Api-Key: {{postman_api_key}}

      请求体部分:

      { "environment": { "name": "New Name", "values": [ "key": "name", "value":"Bruce Wayne" },

              {"key":"occupation", "value": "Vigilante" } ] } }

    示例请求

       成功的请求

       url --location --request PUT "https://api.getpostman.com/environments/{{environment_uid}}"

           --header "Content-Type: application/json"

           --header "X-Api-Key: {{postman_api_key}}"

           --data "{  "environments": { "name": "New Name",

              "values": [ { "key": "name", "value": "Bruce Wayne"},

              {"key": "occupation", "value": "Vigilante" }

             ] } },

    示例响应

     200 - OK

     { "environment" : { "id": "957128dd-84f2-2213-438e-1309521342",

       "name": "New Name", "uid": "421315-957128dd-84f2-2213-438e-1309521342"

    }}

      DEL 删除环境变量

        https://api.getpostman.com/environments/{{environment_uid}}

     这个端点允许给予环境变量的uid来删除一个环境变量。

         xu要API Key作为X-Api-Key请求头文件或apikey URL查询参数。

    头文件HEADERS

      X-Api-Key: {{postman_api_key}}

      示例请求

        环境变量未找到

         url --location --request DELETE "https://api.getpostman.com/environments/{{environment_uid}}"

         --header "X-Api-Key: {{postman_api_key}}"

     示例响应

      404 - 未找到

        {"error" : { "name": "instanceNotFoundError",

          "message": "The specified environment does not exist." }

       }

     IT的技术掌握起来真的要耗费很多时间和精力,本篇耗费了3个小时,还只是初步过了一遍,具体使用不包括。不得不感叹,做IT这么耗时耗精力薪水还那么低,已经不是一开始很多人认为的高薪饭碗了。技术那么多,只掌握一个技术就要耗费很多精力,而工作上的要求很高,不可能让你拿工作项目来练手。做IT是个苦差事啊。

       

     

     

      

    是人是鬼,拉出来溜溜。 是人是熊,靠上去看看。 是龙是虫,用嘴巴讲讲。 是好是赖,用心去窥探。
  • 相关阅读:
    Java学习(零)
    WP7 Toolkit ExpanderView 控件 介绍 01
    WP7 Tip:改变启动页
    WP7 Toolkit LoopingSelector 控件 介绍
    azkaban hdfs plugin 配置
    修改hostname
    hybris Models
    hadoop 2.6 安装配置
    hadoop CDH5.1.0 配置kerberos
    flumengtaildirectorysource 修改调试可用
  • 原文地址:https://www.cnblogs.com/fangyuc/p/10503636.html
Copyright © 2011-2022 走看看