Postman Flows 可以通過(guò)API 請(qǐng)求或直接從Start塊獲取數(shù)據(jù)。本教程展示了 Postman Flows 使用這兩種方法獲取數(shù)據(jù)并在塊之間傳遞數(shù)據(jù)的示例。
內(nèi)容
獲取數(shù)據(jù)并在塊之間傳遞它
這些示例通過(guò)API 請(qǐng)求從工作區(qū)中的現(xiàn)有集合和粘貼到Start塊中的數(shù)據(jù)獲取響應(yīng)數(shù)據(jù)。在這些示例中,整個(gè)響應(yīng)在塊之間傳遞。
通過(guò) API 請(qǐng)求獲取數(shù)據(jù)
在此示例中,發(fā)送請(qǐng)求塊使用集合的 GET 請(qǐng)求獲取數(shù)據(jù)。然后發(fā)送請(qǐng)求塊將所有數(shù)據(jù)傳遞給日志塊。
- 創(chuàng)建一個(gè)名為的集合Random User Collection并使用此 URL 添加 GET 請(qǐng)求:https://randomuser.me/api/。
- 選擇發(fā)送。

- 選擇保存。
- 創(chuàng)建一個(gè)新流并將發(fā)送請(qǐng)求塊連接到啟動(dòng)塊。

- 在“發(fā)送請(qǐng)求”塊中,選擇“添加請(qǐng)求”>“隨機(jī)用戶(hù)集合”>“新請(qǐng)求”。每次流程執(zhí)行時(shí),它將使用您之前創(chuàng)建的隨機(jī)用戶(hù)收集請(qǐng)求中的 GET 請(qǐng)求獲取數(shù)據(jù)。

- 將日志塊連接到發(fā)送請(qǐng)求塊的成功端口。

- 選擇控制臺(tái),然后選擇運(yùn)行。Log塊將整個(gè)響應(yīng)發(fā)送到控制臺(tái),包括請(qǐng)求標(biāo)頭、響應(yīng)標(biāo)頭和響應(yīng)正文。
從 Start 塊獲取數(shù)據(jù)
在此示例中,流從Start塊獲取數(shù)據(jù)并將其傳遞給Evaluate塊。Evaluate塊將整個(gè)響應(yīng)傳遞給變量中的Log塊。
- 創(chuàng)建一個(gè)新流并選擇“開(kāi)始”
塊 中的齒輪圖標(biāo) 。
- 選擇輸入傳入數(shù)據(jù)并粘貼到下面的示例數(shù)據(jù)中。流程將在每次執(zhí)行時(shí)使用此數(shù)據(jù)。{
"results": [
{
"gender": "female",
"name": {
"title": "Miss",
"first": "Astrid",
"last": "Klingenberg"
},
"location": {
"street": {
"number": 2547,
"name": "Lyseskrenten"
},
"city": "Tvedestrand",
"state": "Oppland",
"country": "Norway",
"postcode": "6523",
"coordinates": {
"latitude": "44.5909",
"longitude": "130.7502"
},
"timezone": {
"offset": "+9:00",
"description": "Tokyo, Seoul, Osaka, Sapporo, Yakutsk"
}
},
"email": "astrid.klingenberg@example.com",
"login": {
"uuid": "263e48e9-1d6d-4d18-9458-27b1b7bad1b9",
"username": "lazycat514",
"password": "francois",
"salt": "YAY2fGhq",
"md5": "0ed2300b7aad0843267d658db0f22f2a",
"sha1": "57ef1b1c5cac06feb6712ac863b7c9d6292e400e",
"sha256": "5312eee0d8693e522aa62814fb49fb3239bad5326ca0f37011a97704978a4add"
},
"dob": {
"date": "1984-03-11T08:50:14.752Z",
"age": 38
},
"registered": {
"date": "2003-09-27T19:45:20.432Z",
"age": 19
},
"phone": "57680755",
"cell": "96350131",
"id": {
"name": "FN",
"value": "11038429851"
},
"picture": {
"large": "https://randomuser.me/api/portraits/women/68.jpg",
"medium": "https://randomuser.me/api/portraits/med/women/68.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/women/68.jpg"
},
"nat": "NO"
}
],
"info": {
"seed": "4be1e2e93f6d34ba",
"results": 1,
"page": 1,
"version": "1.4"
}
}
- 選擇Language下拉列表并選擇JSON。

- 將Evaluate塊連接到Start塊。
- 在Evaluate塊中,選擇value1并輸入body。這將從Start塊接收到的所有數(shù)據(jù)分配給變量body。

- 在Evaluate塊中,選擇Start writing an FQL query...并輸入body。這會(huì)將變量中的所有數(shù)據(jù)發(fā)送body到Evaluate塊的輸出。
- 將Log模塊連接到Evaluate模塊。

- 選擇控制臺(tái),然后選擇運(yùn)行。該流從Start塊獲取數(shù)據(jù),將其路由到Evaluate塊,并將整個(gè)響應(yīng)傳遞到Log塊,后者在控制臺(tái)中顯示數(shù)據(jù)。
在塊之間傳遞指定的數(shù)據(jù)
您可以使用變量和流查詢(xún)語(yǔ)言 (FQL)以多種方式從響應(yīng)數(shù)據(jù)中提取特定值。下面的示例在Evaluate塊中使用 FQL 從Startcountry塊中的示例響應(yīng)數(shù)據(jù)中獲取字段值。
- 創(chuàng)建一個(gè)新流并選擇“開(kāi)始”
塊 中的齒輪圖標(biāo) 。
- 選擇輸入傳入數(shù)據(jù)并粘貼到下面的示例數(shù)據(jù)中。流程將在每次執(zhí)行時(shí)使用此數(shù)據(jù)。{
"results": [
{
"gender": "female",
"name": {
"title": "Miss",
"first": "Astrid",
"last": "Klingenberg"
},
"location": {
"street": {
"number": 2547,
"name": "Lyseskrenten"
},
"city": "Tvedestrand",
"state": "Oppland",
"country": "Norway",
"postcode": "6523",
"coordinates": {
"latitude": "44.5909",
"longitude": "130.7502"
},
"timezone": {
"offset": "+9:00",
"description": "Tokyo, Seoul, Osaka, Sapporo, Yakutsk"
}
},
"email": "astrid.klingenberg@example.com",
"login": {
"uuid": "263e48e9-1d6d-4d18-9458-27b1b7bad1b9",
"username": "lazycat514",
"password": "francois",
"salt": "YAY2fGhq",
"md5": "0ed2300b7aad0843267d658db0f22f2a",
"sha1": "57ef1b1c5cac06feb6712ac863b7c9d6292e400e",
"sha256": "5312eee0d8693e522aa62814fb49fb3239bad5326ca0f37011a97704978a4add"
},
"dob": {
"date": "1984-03-11T08:50:14.752Z",
"age": 38
},
"registered": {
"date": "2003-09-27T19:45:20.432Z",
"age": 19
},
"phone": "57680755",
"cell": "96350131",
"id": {
"name": "FN",
"value": "11038429851"
},
"picture": {
"large": "https://randomuser.me/api/portraits/women/68.jpg",
"medium": "https://randomuser.me/api/portraits/med/women/68.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/women/68.jpg"
},
"nat": "NO"
}
],
"info": {
"seed": "4be1e2e93f6d34ba",
"results": 1,
"page": 1,
"version": "1.4"
}
}
- 選擇Language下拉列表并選擇JSON。

- 將Evaluate塊連接到Start塊。
- 在Evaluate塊中,選擇key并輸入body。這將從Start塊接收到的所有數(shù)據(jù)分配給變量body。

- 在Evaluate塊中,選擇Enter FQL query并輸入body.results.location.country。這將使用FQL導(dǎo)航響應(yīng)數(shù)據(jù)并提取字段的值country。
- 將Log模塊連接到Evaluate模塊。

- 選擇控制臺(tái)。
- 選擇運(yùn)行。Start塊將其數(shù)據(jù)發(fā)送到Evaluate塊。Evaluate塊中的 FQL獲取響應(yīng)數(shù)據(jù)中country字段 ( )的值并將其發(fā)送到Log塊。出現(xiàn)在控制臺(tái)中。"Norway""Norway"

更多建議: