Part 5 - Connect a React Native Cup Shop to a FastAPI Backend
Move MugMori beyond local data by designing a typed API service for products and future order requests with FastAPI.
Connect a React Native Cup Shop to a FastAPI Backend
The first four articles used local data so we could learn the mobile UI without waiting for a backend. A real shopping app eventually needs shared products, current prices, inventory, and orders.
This article describes a React Native client consuming a FastAPI service. It is not a claim that this repository's FastAPI runtime has already been implemented.
Separate client types from UI components
export type ProductResponse = {
id: string;
name: string;
description: string;
price: number;
imageUrl: string;
inStock: boolean;
};
Keep API types and request functions separate from Paper components. A CupCard should receive a product object; it should not construct URLs or interpret network errors.
Add a small API service
const API_BASE_URL = 'https://api.example.test';
export async function fetchProducts(): Promise<ProductResponse[]> {
const response = await fetch(API_BASE_URL + '/api/products');
if (!response.ok) throw new Error('Products could not be loaded.');
return response.json() as Promise<ProductResponse[]>;
}
The URL is an example only. A real app should use environment-specific configuration and HTTPS.
Model network states
Network calls can be slow or unavailable. The catalog should have explicit idle, loading, success, and error states. Render a Paper ActivityIndicator while loading and a retry button for errors.
Keep orders trustworthy
The mobile app may display a subtotal, but the server must calculate the final order total from trusted product and promotion data. The client should submit product identifiers, quantities, and options, not a final price the server accepts blindly.
FastAPI can validate requests with Pydantic models and return a stable response shape.
Existing project boundary
The planned architecture for this repository is Django plus FastAPI in one ASGI application. Existing Django routes, templates, admin behavior, and authentication remain Django responsibilities. New public API routes can be placed under an /api prefix.
The verified Django settings module is config.settings, and the verified ASGI import path is config.asgi:application. Those facts describe the repository today; they do not mean the FastAPI integration is complete.
The mobile app owns presentation and temporary UI state. The API owns validation, permissions, current prices, and durable order behavior.