SDKs

Dart / Flutter

Idiomatische Dart-Patterns für Flutter-Apps und Dart-Server

Verwende das http-Package für einfache Fälle oder dio für Interceptors und Retries. http wird unten gezeigt — es kommt mit dem Dart SDK out of the box für Flutter.

pubspec.yaml

dependencies:
  http: ^1.2.2

Konfigurieren

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',
};

Eine Seite distillen

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;
}

Strukturierte Daten extrahieren

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'];
}

Flutter-UI-Tipp

Pack die Aufrufe in einen FutureBuilder, damit die UI nicht blockiert — und lass deinen Dart-Server (nicht die Flutter-App) den API Key in Produktion verwalten.

Bei Batch-Jobs reichst du ein und überlässt einem serverseitigen Webhook-Handler die Arbeit. Siehe Webhooks.

Ein offizielles Dart SDK ist in Entwicklung — schau bald wieder rein.