# Superport API Patterns v8.0 ## What This Really Is Backend API patterns specific to this project. Just code to copy. ## Rust Backend Endpoints ```rust // GET endpoint pattern #[get("/equipment")] async fn get_equipment(db: web::Data) -> Result { let items = Equipment::find_all(&db).await?; Ok(HttpResponse::Ok().json(items)) } // POST with validation #[post("/equipment")] async fn create_equipment( req: web::Json, db: web::Data, ) -> Result { req.validate()?; // Always validate let item = Equipment::create(&db, req.into_inner()).await?; Ok(HttpResponse::Created().json(item)) } ``` ## Frontend API Calls ```dart // Always use this pattern class EquipmentApi { Future>> getEquipments() async { final response = await dio.get('/equipment'); return ApiResponse.fromJson( response.data, (json) => (json as List).map((e) => EquipmentDto.fromJson(e)).toList(), ); } } ``` ## DTO Field Mapping ```dart // Backend fields MUST match exactly @JsonSerializable() class EquipmentDto { @JsonKey(name: 'companies_id') // NOT company_id final int? companiesId; @JsonKey(name: 'warehouses_id') // NOT warehouse_id final int? warehousesId; } ``` ## Error Handling ```dart try { final result = await api.getEquipments(); // Success path } on DioError catch (e) { if (e.response?.statusCode == 404) { // Handle not found } else { // Generic error } } ``` ## Common Endpoints in Project ``` GET /equipment POST /equipment PUT /equipment/:id DELETE /equipment/:id GET /equipment-history POST /equipment-history GET /companies GET /warehouses GET /models GET /vendors ``` --- *Backend owns logic. Frontend just calls.*