SDKs

Dart / Flutter

Patterns Dart idiomatiques pour les apps Flutter et le serveur Dart

Utilise le package http pour les cas simples ou dio pour les intercepteurs et retries. http montré ci-dessous — il est livré avec le SDK Dart d'origine pour Flutter.

pubspec.yaml

dependencies:
  http: ^1.2.2

Configuration

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 une page

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 données structurées

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

Astuce UI Flutter

Enveloppe les appels dans un FutureBuilder pour que l'UI ne bloque pas — et laisse ton serveur Dart (pas l'app Flutter) posséder l'API Key en production.

Pour les batch jobs, soumets puis laisse ton handler webhook côté serveur faire le travail. Voir Webhooks.

Un SDK Dart officiel est en développement — reviens bientôt.