Introduction
Q-Sopa uses a REST API backend hosted on Railway to serve menu categories and products. The API integration is implemented through a centralized service module that provides clean, reusable functions for all data fetching operations.API Architecture
The API follows a simple REST architecture with JSON responses. All API interactions are handled through thesrc/services/api.js module, which exports async functions that wrap native fetch calls.
Base URL
All API requests are made to the production backend:The base URL is defined as a constant in the API service module and is automatically prepended to all endpoint paths.
Service Architecture
The API service (src/services/api.js) provides three core functions:
getCategorias
Fetch all available menu categories
getComidas
Fetch all products across categories
getProductsByCategory
Fetch products filtered by category
Authentication
The Q-Sopa API is currently public and does not require authentication. All endpoints are accessible without API keys or tokens.Request Format
All requests are standard HTTP GET requests that return JSON responses:Response Format
All successful API responses return JSON data:Error Handling
The API service implements consistent error handling across all functions:src/services/api.js
Error Patterns
Each API function:- Makes a fetch request
- Checks the
res.okstatus - Throws a descriptive error if the request failed
- Returns parsed JSON on success
Errors are thrown with Spanish messages matching the application’s locale. Components catch these errors and display them to users.
Error Response Handling
Components using the API should implement try-catch patterns or promise.catch() handlers:
Common Error Scenarios
Network Errors
Status:
!res.okMessage: “Error al cargar [resource]”Handling: Display error message to user, provide retry optionInvalid Category ID
Occurs: When requesting products for non-existent categoryHandling: Check category existence before fetching products
Performance Considerations
Caching Strategy
The current implementation fetches data on demand without caching. Consider implementing:- React Query or SWR for automatic caching and revalidation
- Local Storage for offline-first capabilities
- Memoization for frequently accessed data
Loading States
All API calls should implement loading states to provide user feedback:Integration Best Practices
Centralized Service
Keep all API calls in
src/services/api.js for maintainabilityError Boundaries
Implement React error boundaries to catch API errors gracefully
Loading States
Always show loading indicators during API calls
Error Messages
Display user-friendly error messages in Spanish
Next Steps
Explore API Endpoints
Learn about each API function’s signature, parameters, and responses
Usage Examples
See real implementation examples from the Q-Sopa codebase
