Node.js 用予約サーバー スケルトン
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
これは、Node.js ベースの 標準統合用の API v3 予約サーバーのリファレンス実装です。
前提条件
インストールが必要
スタートガイド
予約サーバーは、説明を目的として、追加のライブラリやフレームワークを使用せずに標準の Node.js を使用して実装されています。他のフレームワークを使用している場合は、この実装を Express.js、MEAN.js、または任意の Node.js ベースのフレームワークに簡単に変更できます。
この実装ではプロトコル バッファ ライブラリも使用せず、単純な JSON シリアル化とその JSON.parse() メソッドと JSON.stringify() メソッドに依存しています。
プロジェクトをダウンロードするには、次のコマンドを実行します。
git clone https://maps-booking.googlesource.com/js-maps-booking-rest-server-v3-skeleton
コードベース全体は、次の 2 つの JavaScript ファイルのみで構成されています。
- bookingserver.js - HTTP サーバー、認証を含むリクエスト処理ロジック
- apiv3methods.js - API v3 インターフェースを実装するメソッド
ファイルをダウンロードしたら、次のコマンドを実行して予約サーバーを起動できます。
node bookingserver.js
スケルトンは、すべての受信リクエストと送信リクエストをコンソールに書き込むため、トレース目的で実行をモニタリングできます。
コードの変更やデバッグに IDE が必要な場合は、Visual Studio Code または任意のエディタを使用できます。Node.js 環境で bookingserver.js を起動し、必要に応じてブレークポイントを設定して、プロジェクトをデバッグします。
予約サーバーのテスト
Booking テスト ユーティリティをダウンロードします。インストールするには、README ページに記載されているインストール手順に沿って操作します。
テスト用に、認証情報を保存するテキスト ファイルを作成する必要があります。ユーザー名とパスワードを 1 行で入力します。たとえば、cred.txt という名前のファイルに次のように入力します。
username:password
また、テスト販売者の在庫状況フィードのローカル コピーも必要です。以下のサンプル コマンドでは、在庫フィードは avail.json です。
これで、次のコマンドを使用して予約サーバーをテストできます。
- HealthCheck メソッドの呼び出しをテストします。
bin/bookingClient -server_addr="localhost:8080" -health_check_test=true -credentials_file="./cred.txt"
- CheckAvailability メソッドの呼び出しをテストします。
bin/bookingClient -server_addr="localhost:8080" -check_availability_test=true -availability_feed="./avail.json" -credentials_file="./cred.txt"
- CreateBooking メソッドと UpdateBooking メソッドの呼び出しをテストします。
bin/bookingClient -server_addr="localhost:8080" -booking_test=true -availability_feed="./avail.json" -credentials_file="./cred.txt"
独自の予約サーバーを実装する場合は、すべてのテストが合格するように(-all_tests=true)、追加のテスト(list_bookings_test、rescheduling_test など)を実行する必要があります。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[[["\u003cp\u003eThis is a Node.js-based reference implementation of the API v3 Booking Server for Standard Integration, allowing developers to understand and build their own booking systems.\u003c/p\u003e\n"],["\u003cp\u003eThe server utilizes basic Node.js functionalities and JSON for serialization, offering flexibility for adaptation to various frameworks like Express.js or MEAN.js.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can clone the provided repository, run the server using a simple command, and leverage debugging tools like Visual Studio Code for development.\u003c/p\u003e\n"],["\u003cp\u003eA Booking test utility and sample commands are provided for validating the functionality of the implemented Booking Server using credentials and an Availability feed.\u003c/p\u003e\n"],["\u003cp\u003eFurther testing with additional commands is encouraged to ensure comprehensive coverage and successful integration with the Booking API.\u003c/p\u003e\n"]]],["This document details a Node.js-based reference implementation of an API v3 Booking Server. It uses standard Node.js and JSON serialization. Key actions include: cloning the project via `git`, starting the server with `node bookingserver.js`, and utilizing the Booking test utility for testing. To test, users must create a credentials file and use an Availability feed. Testing commands are provided for HealthCheck, CheckAvailability, CreateBooking, and UpdateBooking. It encourages comprehensive testing.\n"],null,["# Booking Server Skeleton for Node.js\n\nThis is a reference implementation of\n[API v3 Booking Server for Standard Integration](/actions-center/verticals/local-services/e2e/integration-steps/implement-booking-server)\nbased on Node.js\n\n### Prerequisites\n\nRequires an installation of\n\n- [Node.js](https://nodejs.org/)\n\nGetting Started\n---------------\n\nThe Booking Server is implemented using standard Node.js without any\nadditional libraries or frameworks, for illustration purposes. If you are\nusing any other frameworks, you could easily change this implementation to\nExpress.js, MEAN.js, or any other Node.js-based framework of your choice.\n\nThe implementation is also not using protocol buffer libraries, but instead\nrelies on simple JSON serialization and its JSON.parse() and JSON.stringify()\nmethods.\n\nTo download the project, execute the following command: \n\n```javascript\ngit clone https://maps-booking.googlesource.com/js-maps-booking-rest-server-v3-skeleton\n```\n\nThe entire code base consists of only two JavaScript files:\n\n- bookingserver.js - HTTP server and requests handling logic, including authentication\n- apiv3methods.js - methods implementing API v3 interface\n\nAfter you download the files, you can start the Booking Server by running\nthe command: \n\n```javascript\nnode bookingserver.js\n```\n\nThe skeleton writes all incoming and outgoing requests to the console, so you\ncan monitor its execution for tracing purposes.\n\nShould you need an IDE for code changes or debugging, you can use\n[Visual Studio Code](https://code.visualstudio.com/) or any other\neditor of your choice. Debug the project by starting bookingserver.js in the\nNode.js environment and set breakpoints where needed.\n\nTesting your Booking Server\n---------------------------\n\nDownload\n[Booking test utility](https://maps-booking.googlesource.com/maps-booking-v3/). To install it, follow the provided installation\ninstructions in its README page.\n\nFor the tests, you need to create a text file to store your credentials.\nEnter your username and password on a single line, for example, in a file\nnamed cred.txt:\n\nusername:password\n\nYou also need a local copy of an Availability feed for your test merchants.\nIn the samples commands below, the Availability feed is avail.json.\n\nNow, you can test your Booking Server with these commands:\n\n- Test calls to HealthCheck method: \n\n ```javascript\n bin/bookingClient -server_addr=\"localhost:8080\" -health_check_test=true -credentials_file=\"./cred.txt\"\n ```\n- Test calls to CheckAvailability method: \n\n ```javascript\n bin/bookingClient -server_addr=\"localhost:8080\" -check_availability_test=true -availability_feed=\"./avail.json\" -credentials_file=\"./cred.txt\"\n ```\n- Test calls to CreateBooking and UpdateBooking methods: \n\n ```javascript\n bin/bookingClient -server_addr=\"localhost:8080\" -booking_test=true -availability_feed=\"./avail.json\" -credentials_file=\"./cred.txt\"\n ```\n\nAs you are implementing your own Booking Server, you may need to run\nadditional tests against it (e.g. list_bookings_test, rescheduling_test, etc)\nwith the goal of all tests passing (-all_tests=true)."]]