rhttp 0.5.2 copy "rhttp: ^0.5.2" to clipboard
rhttp: ^0.5.2 copied to clipboard

Make HTTP requests using Rust for Flutter developers. It uses FFI to call Rust functions from Dart. On the Rust side, it uses reqwest to make HTTP requests.

example/lib/main.dart

// ignore_for_file: avoid_print

import 'package:flutter/material.dart';
import 'package:rhttp/rhttp.dart';

Future<void> main() async {
  await Rhttp.init();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  HttpTextResponse? response;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Test Page'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ElevatedButton(
                onPressed: () async {
                  try {
                    final res = await Rhttp.get(
                      'https://reqres.in/api/users',
                      query: {'page': '5'},
                      settings: const ClientSettings(
                        httpVersionPref: HttpVersionPref.http3,
                      ),
                    );
                    setState(() {
                      response = res;
                    });
                  } catch (e, st) {
                    print(e);
                    print(st);
                  }
                },
                child: const Text('Test'),
              ),
              if (response != null) Text(response!.version.toString()),
              if (response != null) Text(response!.statusCode.toString()),
              if (response != null) Text(response!.body.substring(0, 100).toString()),
              // if (response != null) Text(response!.headers.toString()),
            ],
          ),
        ),
      ),
    );
  }
}
39
likes
0
pub points
91%
popularity

Publisher

verified publishertienisto.com

Make HTTP requests using Rust for Flutter developers. It uses FFI to call Rust functions from Dart. On the Rust side, it uses reqwest to make HTTP requests.

Repository (GitHub)
View/report issues

Topics

#http #rust #ffi #http2 #http3

Funding

Consider supporting this project:

github.com

License

unknown (license)

Dependencies

flutter, flutter_rust_bridge, freezed_annotation, http, meta, plugin_platform_interface

More

Packages that depend on rhttp