SDKs
Dart / Flutter
Patrones idiomáticos de Dart para apps de Flutter y servidores Dart
Usa el paquete http para casos simples o dio para interceptores y reintentos. http se muestra abajo — viene con el SDK de Dart out of the box para Flutter.
pubspec.yaml
dependencies:
http: ^1.2.2Configuración
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
const api = 'https://openapi.thunderbit.com/openapi/v1';
final headers = <String, String>{
'Authorization': 'Bearer ${Platform.environment['THUNDERBIT_API_KEY']}',
'Content-Type': 'application/json',
};Distill de una página
Future<String> distill(String url) async {
final res = await http.post(
Uri.parse('$api/distill'),
headers: headers,
body: jsonEncode({'url': url}),
);
if (res.statusCode >= 400) throw Exception(res.body);
final body = jsonDecode(res.body) as Map<String, dynamic>;
return body['data']['markdown'] as String;
}Extract de datos estructurados
Future<Map<String, dynamic>> extract(String url) async {
final res = await http.post(
Uri.parse('$api/extract'),
headers: headers,
body: jsonEncode({
'url': url,
'schema': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'price': {'type': 'number'},
},
'required': ['name', 'price'],
},
}),
);
return (jsonDecode(res.body) as Map<String, dynamic>)['data'];
}Consejo para UI de Flutter
Envuelve las llamadas en un FutureBuilder para que la UI no se bloquee — y deja que tu servidor Dart (no la app de Flutter) sea dueño de la API Key en producción.
Para batch jobs, envía y deja que tu handler de webhook del lado del servidor haga el trabajo. Ver Webhooks.
Un SDK oficial de Dart está en desarrollo — vuelve pronto.