在 for-in 循环中发出 HTTP 请求

在 for-in 循环中发出 HTTP 请求。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

YAML

- getUserIDs:
    call: http.get
    args:
      url: https://example.com/getUserIDs
    result: userIds
- saveUserInfo:
    for:
      value: uid
      in: ${userIds}
      steps:
        - tryStep:
            try:
              steps:
                - get:
                    call: http.get
                    args:
                      url: ${"https://example.com/getUserInfo?userId=" + string(uid)}
                    result: userInfo
                - post:
                    call: http.post
                    args:
                      url: ${"https://example.com/saveUserInfo?userId=" + string(uid)}
                      body: ${userInfo}
            except:
              as: e
              steps:
                - knownErrors:
                    switch:
                      - condition: ${not("HttpError" in e.tags)}
                        return: '${"Connection problem with userID: " + string(uid)}'
                - unhandledErrors:
                    raise: ${e}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器