This tutorial demonstrates how to work with Couchbase's Data API to manage airport data from the travel-sample dataset.
This provides a comprehensive Airport Information System that manages airport data and provides related travel information from the Couchbase travel-sample dataset.
Choose your preferred serverless platform to get started:
- AWS Lambda: View Tutorial
- Cloudflare Workers: View Tutorial
- Azure Functions: View Tutorial
- Google Cloud Functions: View Tutorial
GET /airports/{document_key}- Retrieve an airport documentPOST /airports- Create a new airport documentPUT /airports/{document_key}- Update an existing airport documentDELETE /airports/{document_key}- Delete an airport document
GET /airports/{airport_code}/routes- Find routes for a specific airportGET /airports/{airport_code}/airlines- Find airlines that service a specific airport
GET /airports/{airport_id}/hotels/nearby/{distance}- Find hotels near a specific airport within a specific distance
- Couchbase Capella cluster with Data API enabled
- Couchbase travel-sample bucket loaded
To connect to your Capella cluster, please follow the instructions.
Specifically, you need to do the following:
- Create database credentials to access the travel-sample bucket (Read and Write permissions) used in the application
- Allow access to the Cluster from the IP on which the application is running
The following Couchbase Data API credentials are required:
DATA_API_USERNAME- Your Couchbase database usernameDATA_API_PASSWORD- Your Couchbase database passwordDATA_API_ENDPOINT- Your Couchbase Data API endpoint URL
The hotel proximity search functionality requires a Full Text Search index with geo-spatial mapping on hotel documents. The index (hotel-geo-index) enables proximity searches on hotel documents and must be created before using the hotel search functionality.
A common Node.js script is provided to create the required geo-spatial FTS index. See scripts/README.md for detailed instructions on how to create the FTS index.
The following examples demonstrate the API endpoints that interface with Couchbase's Data API:
curl https://your-api-endpoint/airports/airport_1254curl -X POST https://your-api-endpoint/airports \
-H "Content-Type: application/json" \
-d '{
"airportname": "Test Airport",
"city": "Test City",
"country": "Test Country",
"faa": "TST",
"geo": {
"alt": 100,
"lat": 34.0522,
"lon": -118.2437
},
"icao": "KTST",
"id": "airport_9999",
"type": "airport",
"tz": "America/Los_Angeles"
}'Note: The id field in the request body becomes the document key in Couchbase and the rest of document will be the value.
curl -X PUT https://your-api-endpoint/airports/airport_1254 \
-H "Content-Type: application/json" \
-d '{
"airportname": "Updated Airport",
"city": "Updated City",
"country": "Updated Country",
"faa": "UPD",
"geo": {
"alt": 200,
"lat": 35.0522,
"lon": -119.2437
},
"icao": "KUPD",
"id": 1254,
"type": "airport",
"tz": "America/Los_Angeles"
}'curl -X DELETE https://your-api-endpoint/airports/airport_1254curl https://your-api-endpoint/airports/LAX/routescurl https://your-api-endpoint/airports/LAX/airlinescurl https://your-api-endpoint/airports/airport_1254/hotels/nearby/50kmPath Parameters:
airport_id: Airport document ID (required) - e.g., airport_1254, airport_1255distance: Search radius (required) - e.g., 50km, 10km
Prerequisites for hotel search: Make sure you have created the FTS index (hotel-geo-index) before using this endpoint.
Apache 2.0
