スタート アップ ガイド
CLI をインストールし、JavaScript または TypeScript 関数プロジェクトをスキャフォールディングして、最初の関数をローカルで実行します。
このページでは、CLI のインストール、プロジェクトのスキャフォールディング、および最初の JavaScript 関数のローカル実行について説明します。
前提条件
- Node.js 20 以降。
uipCLI と関数ツール:
npm install -g @uipath/cli
uip tools install @uipath/function-tool
npm install -g @uipath/cli
uip tools install @uipath/function-tool
- パブリッシュおよび呼び出しに使用する、Orchestrator へのアクセス権を持つ UiPath アカウント。
プロジェクトのスキャフォールディング
uip function new my-functions --kind http
cd my-functions
uip function new my-functions --kind http
cd my-functions
--kind http creates a project of HTTP functions (targetRuntime javascript-server). --kind job, the default, creates a project of job functions (javascript). TypeScript is the default language; pass -l js for JavaScript, or --empty to skip the sample function.
The project contains:
| ファイル | 目的 |
|---|---|
functions/hello.ts | Your function. Each file directly in functions/ is one function. |
functions/_*.ts | Shared helpers. A file whose name starts with an underscore is not a function. |
uipath.json | The project's targetRuntime and the list of functions. The CLI keeps the list in sync with functions/. |
project.uiproj | The project name and its main function. |
package.jsonpackage-lock.json、tsconfig.json | 標準のプロジェクト ファイル |
最初の関数を記述する
import { defineFunction, defineSchema } from "@uipath/coded-functions-js-sdk";
interface HelloInput {
name: string;
}
interface HelloOutput {
message: string;
}
export default defineFunction({
name: "hello",
method: "POST",
path: "/hello",
input: defineSchema<HelloInput>(),
output: defineSchema<HelloOutput>(),
handler: async (input) => ({ message: `Hello, ${input.name}!` }),
});
import { defineFunction, defineSchema } from "@uipath/coded-functions-js-sdk";
interface HelloInput {
name: string;
}
interface HelloOutput {
message: string;
}
export default defineFunction({
name: "hello",
method: "POST",
path: "/hello",
input: defineSchema<HelloInput>(),
output: defineSchema<HelloOutput>(),
handler: async (input) => ({ message: `Hello, ${input.name}!` }),
});
defineSchema<T>() は TypeScript インターフェイスから JSON スキーマを派生させるため、同じ型がコントラクトを宣言し、ハンドラーに型付けします。JavaScript プロジェクトでは、代わりに JSON スキーマ オブジェクトを渡します。
The method and path make this an HTTP function. A job function declares neither. See Building JavaScript functions.
ローカルで実行する
uip function serve
uip function serve
これにより、ホット リロード サーバーが http://localhost:7070で起動します。関数を呼び出します。
curl -X POST http://localhost:7070/hello \
-H "Content-Type: application/json" \
-d '{"name":"Alice"}'
# {"message":"Hello, Alice!"}
curl -X POST http://localhost:7070/hello \
-H "Content-Type: application/json" \
-d '{"name":"Alice"}'
# {"message":"Hello, Alice!"}
To reach Orchestrator from a local run, put UIPATH_ACCESS_TOKEN, UIPATH_BASE_URL, UIPATH_ORG_ID and UIPATH_TENANT_ID in a .env file at the project root. serve loads it.
次のステップ
- Building JavaScript functions — HTTP and job functions, contracts, and errors.
- HTTP トリガーとルーティング — ルート、パス パラメーター、デプロイされた関数の呼び出し。
- パッケージ化してパブリッシュする — Orchestrator にデプロイします。
- CLI リファレンス — すべてのコマンドとフラグ。