Skip to content

Commit 68e45c0

Browse files
committed
Revised Tutorial
1 parent 30da98e commit 68e45c0

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

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

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ In this tutorial, you’ll build a flight meal ordering system that:
3434

3535
What You’ll Learn?
3636

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
37+
- How to set up Couchbase Edge Server on your local machine.
38+
- How to configure it to synchronize data with a remote Capella App Services instance.
39+
- How to deploy and run a React-based seatback meal-ordering web application that communicates with Couchbase Edge Server over a REST API.
40+
- Observe how the application continues to function and store data offline even when there is no internet connectivity, and then automatically syncs changes once the connection returns.
4041

4142
## Architecture Overview
4243

@@ -170,33 +171,27 @@ Follow these steps to set up and run the application locally on the same machine
170171
EDGE_SERVER_BASE_URL="https://localhost:60000"
171172
```
172173

173-
* **Explore the Code**:
174-
175-
Fetching Meal Options (Business Class):
174+
* **Edge Server REST Calls in React**:
175+
In the web app, you might see code making REST requests to the Edge Server base URL. For example, to fetch the meal of business class:
176176
```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");
177+
export const fetchBusinessMeal = async () => {
178+
try {
179+
const response = await api.fetch("/american234.AmericanAirlines.AA234/businessmeal");
180+
if (!response) {
181+
const errorData = await response.text();
182+
throw new Error(errorData || "Failed to fetch businessmeal data");
183+
}
184+
return response as MealDoc;
185+
} catch (error) {
186+
if (error instanceof Error) {
187+
throw new Error(`Failed to fetch businessmeal data: ${error.message}`);
194188
}
189+
throw new Error("An unknown error occurred");
195190
}
196-
);
191+
}
197192
```
198193

199-
Placing an Order:
194+
To place an Order:
200195
```js
201196
const updateInventoryData = async (
202197
inventory: InventoryDoc,
@@ -212,7 +207,17 @@ Placing an Order:
212207
};
213208
```
214209

215-
How are we handling changes in the order?
210+
The below api is used to handle real-time changes to orders using the Edge Server's changes feed API. Let's break it down:
211+
212+
- `_changes?feed=continuous` - This establishes a continuous feed connection that stays open to receive updates in real-time
213+
- `include_docs=true` - Includes the full document content with each change notification
214+
- `heartbeat=600` - Sends an empty line every 600ms to keep the connection alive
215+
- `since=now` - Only get changes that occur after the feed is established
216+
- `filter=doc_ids&doc_ids=businessinventory` - Filter to only receive changes for the businessinventory document
217+
- The request includes basic authentication headers and uses an AbortController to allow canceling the feed
218+
219+
This allows the web app to react immediately when inventory changes occur from other seats placing orders.
220+
216221
```js
217222
const response = await fetch(
218223
`/american234.AmericanAirlines.AA234/_changes?feed=continuous&include_docs=true&heartbeat=600&since=now&filter=doc_ids&doc_ids=businessinventory`,
@@ -264,6 +269,9 @@ curl --location 'https://localhost:60000/american234.AmericanAirlines.AA234/busi
264269
--header 'Authorization: Basic c2VhdHVzZXI6cGFzc3dvcmQ='
265270
```
266271

272+
## Conclusion
273+
By walking through this tutorial, you have explored not just how to run the application, but also why Couchbase Edge Server plays a crucial role in offline-first scenarios. You have seen how integrating Edge Server on the aircraft side and using Capella App Services allows you to elegantly synchronize data once connectivity is restored. You also saw how the seatback React app, using the Edge Server’s REST API, can continue to function even without an internet connection.
274+
267275
## Reference Documentation
268276
- [Couchbase Edge Server](https://docs.couchbase.com/couchbase-edge-server/current/get-started/get-started-landing.html)
269277
- [Capella](https://docs.couchbase.com/cloud/get-started/intro.html)

0 commit comments

Comments
 (0)