适用于 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):2024-11-26。
[null,null,["最后更新时间 (UTC):2024-11-26。"],[[["This 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."],["The server utilizes basic Node.js functionalities and JSON for serialization, offering flexibility for adaptation to various frameworks like Express.js or MEAN.js."],["Developers can clone the provided repository, run the server using a simple command, and leverage debugging tools like Visual Studio Code for development."],["A Booking test utility and sample commands are provided for validating the functionality of the implemented Booking Server using credentials and an Availability feed."],["Further testing with additional commands is encouraged to ensure comprehensive coverage and successful integration with the Booking API."]]],["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"]]