getStudentInfo method
Recupera le informazioni dello studente tramite API REST
Implementation
Future<Student> getStudentInfo(String studentID) async {
// Costruzione dell'URL
final url = Uri.parse('$endpoint/studente/$studentID?ingresso=$token');
// Effettua la richiesta HTTP
final response = await http.get(
url,
headers: {'Accept': 'application/json'},
);
// Gestisce la risposta
if (response.statusCode == 200) {
final Map<String, dynamic> data = json.decode(response.body);
if (data['ritorno'] != null) {
return Student.fromJson(data['ritorno']);
} else {
throw Exception('Risposta API non valida: manca il campo "ritorno".');
}
} else {
throw Exception('Errore nella richiesta: ${response.statusCode} - ${response.reasonPhrase}');
}
}