Skip to content

Commit 30da98e

Browse files
committed
Revised Tutorial
1 parent e2113ec commit 30da98e

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

tutorial/markdown/mobile/couchbase-edge-server/edge-server-demo-meal-app.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# frontmatter
33
path: "/tutorial-couchbase-edge-server-demo"
4-
title: "Explore Couchbase Edge Server with seat back application"
4+
title: "Building an Offline-First Airline Meal Ordering App with Couchbase Edge Server"
55
short_title: "Couchbase Edge Server Demo"
66
description:
77
- Learn how to set up Couchbase Edge Server
@@ -24,7 +24,32 @@ length: 45 Mins
2424

2525
## Introduction
2626

27-
The sample React-based web application simulates an airline seat back application, that allows users in business and economy class to place their in-flight meal orders. The sample app leverages **Couchbase Edge Server** for data storage and processing at the edge, simulating a disconnected offline experience within an aircraft. The seatback web app accesses Edge Server via a RESTful interface. When there is Internet connectivity, the **Edge Server** syncs data with remote Capella App Services.
27+
Imagine you’re on a 10-hour international flight. Passengers want to order meals, but the plane has unstable internet connection. How do you ensure orders are captured reliably and synced to the cloud? This is where Couchbase Edge Server shines.
28+
29+
In this tutorial, you’ll build a flight meal ordering system that:
30+
31+
- Works offline using Edge Server, a lightweight database for edge devices.
32+
- Syncs seamlessly with the cloud via Capella App Services when connectivity resumes.
33+
- Uses a React frontend to simulate seatback screens for business/economy classes.
34+
35+
What You’ll Learn?
36+
37+
- Why Edge Server solves offline data challenges
38+
- How to sync edge data with the cloud
39+
- How to design APIs for offline resilience //fix
40+
41+
## Architecture Overview
42+
43+
- Couchbase Edge Server
44+
- Lightweight (~10MB) database for edge devices (e.g., aircraft servers).
45+
- Provides REST APIs for web/mobile apps.
46+
- Stores data locally and syncs with the cloud when online.
47+
- Capella App Services
48+
- Manages secure sync between Edge Server and the cloud.
49+
- Acts as the "source of truth" for meal inventory and orders.
50+
- React Web App
51+
- Simulates seatback ordering screens.
52+
- Talks directly to Edge Server via REST.
2853

2954
## Setup & Technology Stack
3055

@@ -145,6 +170,62 @@ Follow these steps to set up and run the application locally on the same machine
145170
EDGE_SERVER_BASE_URL="https://localhost:60000"
146171
```
147172

173+
* **Explore the Code**:
174+
175+
Fetching Meal Options (Business Class):
176+
```js
177+
export const fetchBusinessMeal = createAsyncThunk<MealDoc>(
178+
"meal/fetchBusinessMeal",
179+
async () => {
180+
try {
181+
const response = await api.fetch("/american234.AmericanAirlines.AA234/businessmeal");
182+
183+
if (!response) {
184+
const errorData = await response.text();
185+
throw new Error(errorData || "Failed to fetch businessmeal data");
186+
}
187+
188+
return response as MealDoc;
189+
} catch (error) {
190+
if (error instanceof Error) {
191+
throw new Error(`Failed to fetch businessmeal data: ${error.message}`);
192+
}
193+
throw new Error("An unknown error occurred");
194+
}
195+
}
196+
);
197+
```
198+
199+
Placing an Order:
200+
```js
201+
const updateInventoryData = async (
202+
inventory: InventoryDoc,
203+
revId: string
204+
): Promise<InventoryDoc> => {
205+
return api.fetch(
206+
`/american234.AmericanAirlines.AA234/businessinventory?rev=${revId}`,
207+
{
208+
method: "PUT",
209+
body: JSON.stringify(inventory),
210+
}
211+
);
212+
};
213+
```
214+
215+
How are we handling changes in the order?
216+
```js
217+
const response = await fetch(
218+
`/american234.AmericanAirlines.AA234/_changes?feed=continuous&include_docs=true&heartbeat=600&since=now&filter=doc_ids&doc_ids=businessinventory`,
219+
{
220+
headers: {
221+
'Authorization': `Basic ${credentials}`,
222+
'Accept': 'application/json'
223+
},
224+
signal: abortController.signal
225+
}
226+
);
227+
```
228+
148229
* **Start the Development Server**:
149230
Launch the application in development mode using:
150231
```bash

0 commit comments

Comments
 (0)