هيكل خادم الحجز لنظام التشغيل Node.js
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
هذا هو نموذج تنفيذ مرجعي لمحاولة
استخدام خادم الحجز في الإصدار 3 من واجهة برمجة التطبيقات لعملية الدمج العادية
استنادًا إلى Node.js.
المتطلبات الأساسية
يتطلب تثبيت
البدء
يتم تنفيذ خادم الحجز باستخدام 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 - طرق تنفيذ واجهة الإصدار 3 من واجهة برمجة التطبيقات
بعد تنزيل الملفات، يمكنك بدء "خادم الحجز" من خلال تنفيذ
الأمر التالي:
node bookingserver.js
يُسجِّل الهيكل جميع الطلبات الواردة والصادرة في وحدة التحكّم، حتى تتمكّن
من تتبُّع تنفيذه لأغراض التتبُّع.
إذا كنت بحاجة إلى بيئة تطوير متكاملة لإجراء تغييرات على الرموز البرمجية أو تصحيح الأخطاء، يمكنك استخدام IDE
Visual Studio Code أو أي IDE
آخر من اختيارك. يمكنك تصحيح أخطاء المشروع من خلال بدء bookingserver.js في بيئة
Node.js وضبط نقاط التوقف عند الحاجة.
اختبار خادم الحجز
نزِّل
أداة اختبار الحجز. لتثبيته، اتّبِع تعليمات التثبيت
المقدَّمة في صفحة README.
لإجراء الاختبارات، عليك إنشاء ملف نصي لتخزين بيانات الاعتماد.
أدخِل اسم المستخدم وكلمة المرور في سطر واحد، على سبيل المثال، في ملف
باسم 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"
أثناء تنفيذ "خادم الحجز" الخاص بك، قد تحتاج إلى إجراء
اختبارات إضافية عليه (مثل list_bookings_test وrescheduling_test وما إلى ذلك)
بهدف اجتياز جميع الاختبارات (-all_tests=true).
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis is a Node.js-based reference implementation of the API v3 Booking Server for Standard Integration.\u003c/p\u003e\n"],["\u003cp\u003eThe server uses simple JSON serialization and can be easily adapted to various Node.js frameworks.\u003c/p\u003e\n"],["\u003cp\u003eYou can download, run, and debug the server using basic Node.js commands and tools.\u003c/p\u003e\n"],["\u003cp\u003eA provided Booking test utility enables testing HealthCheck, CheckAvailability, CreateBooking, and UpdateBooking methods.\u003c/p\u003e\n"],["\u003cp\u003eFor comprehensive testing, consider running additional tests against your Booking Server implementation.\u003c/p\u003e\n"]]],["This Node.js-based reference implementation of the API v3 Booking Server uses standard Node.js and JSON serialization. To use it, clone the project via `git clone https://maps-booking.googlesource.com/js-maps-booking-rest-server-v3-skeleton`. The server, contained in `bookingserver.js` and `apiv3methods.js`, can be started with `node bookingserver.js`. Testing requires downloading the Booking test utility and creating a credentials file. Test commands for HealthCheck, CheckAvailability, CreateBooking, and UpdateBooking are provided, using sample feed and credentials files.\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/reservations/waitlists/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)."]]