适用于 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
整个代码库仅包含两个 JavaScript 文件:
- bookingserver.js - HTTP 服务器和请求处理逻辑,包括身份验证
- apiv3methods.js - 实现 API v3 接口的方法
下载文件后,您可以通过运行以下命令启动预订服务器:
node bookingserver.js
该框架会将所有传入和传出请求写入控制台,以便您监控其执行情况以进行跟踪。
如果您需要使用 IDE 进行代码更改或调试,可以使用 Visual Studio Code 或您选择的任何其他编辑器。在 Node.js 环境中启动 bookingserver.js 并根据需要设置断点,以调试项目。
测试预订服务器
下载预订测试实用程序。如需安装该插件,请按照其自述文件页面中提供的安装说明操作。
对于测试,您需要创建一个文本文件来存储凭据。
在单独的一行中输入您的用户名和密码,例如在名为 cred.txt 的文件中:
username:password
您还需要为测试商家提供库存状况 Feed 的本地副本。
在以下示例命令中,播出信息 Feed 是 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"
由于您要实现自己的预订服务器,因此可能需要针对它运行其他测试(例如 list_bookings_test、rescheduling_test 等),以确保所有测试都通过 (-all_tests=true)。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\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)."]]