bloomBUILD•SHIP•BLOOM
.md
Networking

HTTP Client & Interceptors

Lightweight HTTP client with interceptor pipelines, automatic JWT refresh, and retry mechanisms.

BloomHttpClient Setup

lib/services/api_service.dart
dart
// lib/services/api_service.dart
import 'package:bloom_framework/bloom.dart';

class ApiService {
  final client = BloomHttpClient(
    baseUrl: 'https://api.bloom.dev/v1',
    timeout: const Duration(seconds: 15),
    interceptors: [
      BloomAuthInterceptor(
        tokenProvider: () => inject<AuthService>().token.value,
      ),
      BloomLoggingInterceptor(),
    ],
  );

  Future<List<Post>> fetchPosts() async {
    final response = await client.get('/posts');
    return (response.data as List).map((json) => Post.fromJson(json)).toList();
  }
}