最初のワークフローをデプロイする

現在の曜日を検索キーワードとして Wikipedia API に渡します。関連する Wikipedia 記事のリストが返されます。

コードサンプル

Node.js

このサンプルを試す前に、クライアント ライブラリを使用した Workflows クイックスタートNode.js の手順に沿って設定を行ってください。 詳細については、Workflows Node.js API のリファレンス ドキュメントをご覧ください。

Workflows に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

        },
        workflowId: WORKFLOW_ID,
      });
    }
  });

  it('should execute the quickstart', async () => {
    // Execute workflow, with long test timeout
    const result = execSync(
      `node --loader ts-node/esm ./index.ts ${PROJECT_ID} ${LOCATION_ID} ${WORKFLOW_ID}`
    );

    assert.strictEqual(
      result.length > 0,
      true,
      'Quickstart must return non-empty result'
    );
  }).timeout(5000);
});

YAML

- getCurrentTime:
    call: http.get
    args:
      url: https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
    result: currentTime
- readWikipedia:
    call: http.get
    args:
      url: https://en.wikipedia.org/w/api.php
      query:
        action: opensearch
        search: ${currentTime.body.dayOfWeek}
    result: wikiResult
- returnResult:
    return: ${wikiResult.body[1]}

次のステップ

他の Google Cloud プロダクトのコードサンプルを検索およびフィルタするには、Google Cloud サンプル ブラウザをご覧ください。