A fast HTTP client for Flutter. One C++ engine, five platforms, the same
behaviour on all of them — and the same API on web.
Built with Nitro for Flutter
— the FFI bridge that makes the C++ call cheap enough to be worth making.
import 'package:nitro_http/nitro_http.dart';
final res = await fetch('https://api.example.com/users/42');
print(res.bodyToJson()); // parsed JSON, decoded with the response's charset
print(res.version.label); // HTTP/3 — negotiated for you, not configured
Every request goes to a libcurl engine written in C++, called straight over
FFI — no platform channel, and no second implementation to disagree with the
first.
|
|
| Protocols |
HTTP/1.1 · HTTP/2 · HTTP/3 (QUIC) · WebSockets |
| Transfers |
streaming both ways · upload & download progress · cancellation · per-request timings · resumable via byte ranges |
| Security |
TLS 1.2/1.3 · SPKI pinning, per client or per request · mTLS · custom roots · DNS-over-HTTPS |
| Caching |
RFC 9111 subset — Cache-Control, ETag, Last-Modified, 304 revalidation · prefetch |
| Plumbing |
interceptors · request logging · retry with backoff · cookie jar · HTTP and SOCKS5 proxies · connection pool |
| Platforms |
iOS · Android · macOS · Windows · Linux · Web (via fetch, reduced) |
One engine means proxies, pinning, redirects, timeouts and cookies behave
identically on all five. There is no "works differently on Android".
Why you might want it
- Fast in the shape a real screen loads. Small and large requests
interleaved — fastest in 9 runs out of 9 on every platform measured, and
1.75x the requests per second of the next-best client on Android.
See the charts.
- Features
dart:io cannot reach. HTTP/3, TLS pinning, mTLS,
DNS-over-HTTPS, a disk cache and transfer timings. package:http, dio and
retrofit all sit on dart:io's socket layer, which has no knobs for these —
this package owns its transport, so that is where they live.
- One engine, one behaviour. Nothing to rediscover per platform once you are
in production.
- Drop-in adapters. Already on
package:http or dio? Change one line and
keep every call site.
- Honest about limits. HTTP/1.1-only WebSockets, ~3–4.8 MB per ABI, and a
web build that runs on
fetch rather than the engine. All of it in
Limitations, not buried.
How fast is it
Release builds on real hardware, against dart:io, package:http, dio and
rhttp — all five hitting the same in-process server in the same run.
Each panel's "wins N/9" note is what separates a result from a coin flip — bar
length cannot show it. Where it loses, why, and how to reproduce any of this:
the full benchmark record.
Setup
flutter pub add nitro_http
Requires Dart ^3.12.2 and Flutter >=3.3.0. There is no manual step: the
native engine is fetched as a checksum-pinned prebuilt the first time you build.
What the first build does. On web there is nothing to fetch or compile —
the engine is not used there. On the native platforms it downloads the slice for
each ABI you are building — about 12 MB for a three-ABI Android APK — and compiles the engine,
which adds roughly 11 seconds over a plain Flutter app. Everything lands in a
per-machine cache (~/.cache/nitro_http, %LOCALAPPDATA% on Windows) keyed by
the dependency release, so later projects and package upgrades reuse it and
flutter clean does not throw it away.
Platform support
| Platform |
Requirement |
Anything to do? |
| Android |
minSdk 24 · arm64-v8a, armeabi-v7a, x86_64 |
No |
| iOS |
13.0+, device and simulator · Swift Package Manager |
No |
| macOS |
10.15+ · Swift Package Manager |
Yes — one entitlement, below |
| Windows |
x64 |
No |
| Linux |
x64, arm64 |
No |
| Web |
any browser Flutter supports |
No — but it runs on fetch, not the engine |
iOS and macOS build through Swift Package Manager, which Flutter uses by
default. There is no podspec, so an app that turns Swift Package Manager off
cannot build the plugin.
macOS: the one required step
A sandboxed macOS app needs the network-client entitlement or every request
fails with "connection refused". flutter create does not add it, so a new
app will hit this:
<key>com.apple.security.network.client</key>
<true/>
Add it to both macos/Runner/DebugProfile.entitlements and
macos/Runner/Release.entitlements.
Web
The package compiles and runs on web, but not on the engine: a browser hands
native code no TCP or UDP socket, so libcurl has nothing to talk through.
Compiling libcurl to wasm is possible — libcurl.js
does exactly that with Emscripten and Mbed TLS — but it does not remove that
limit, it relocates it. Sockets are tunnelled over a WebSocket to a
Wisp relay you have to
operate, so every request depends on infrastructure you run; HTTP/3 is absent
and HTTP/2 only exists through the proxy; and it adds ~550 KB and a second TLS
stack. It earns its keep when you specifically need to bypass CORS or drive raw
sockets from a page. For an HTTP client it is a steep price, so this package
does not take it.
fetch is the transport a page actually has, so on web the same API is served
by it, and the code you write does not change:
final client = NitroHttpClient(settings: const ClientSettings());
final res = await client.get('https://api.example.com/users');
What still works: every verb, headers, request and response bodies, streamed
responses, redirects, cancellation, status handling, interceptors and retry —
plus timeouts, download progress, per-request CacheMode, and per-phase
HttpTimings read from the browser's Resource Timing entries.
HttpTimings means the same thing on every platform: each figure is time from
the start of the request, matching CURLINFO_*_TIME_T natively. A reused
connection reports zero DNS and connect on both. Cross-origin responses are
zeroed by the browser unless the server sends Timing-Allow-Origin, leaving
only the total real.
What does not, and why:
|
|
TLS settings — pinning, mTLS, custom roots, insecure() |
the browser owns TLS; a page cannot see or override it |
| proxies, DNS overrides, DoH |
not exposed to a page |
| HTTP version selection |
the browser negotiates; you get what it picks |
| connection pool |
not observable from a page |
| the cookie jar |
the browser manages cookies. They go to the page's own origin; crossOriginCredentials: true sends them to other origins too |
| the disk cache |
the browser's HTTP cache applies instead |
| streamed uploads |
streamed where the browser allows a ReadableStream body (Chrome), buffered elsewhere |
WebSocket headers, pingInterval, TLS |
the browser performs the upgrade and owns them |
These throw NitroHttpConfigurationException rather than being ignored — a
pin that silently stops being checked is worse than a build that stops working.
To share one configuration across native and web, opt out instead of branching
on kIsWeb at every call site:
const ClientSettings(
tlsSettings: TlsSettings(pinnedSpkiSha256: ['sha256//...']),
unsupportedSettings: UnsupportedSettingPolicy.ignore,
);
The pin then applies natively and is dropped in the browser. It is opt-in
because choosing it means accepting that those settings — the security ones
included — do nothing on web.
Check the install
The engine reports what it was actually linked against, which is the quickest
way to confirm a build picked up the vendored slice rather than a system
libcurl:
print(NitroHttp.engineVersion); // libcurl/8.23.0 BoringSSL … ngtcp2/1.25.0
print(NitroHttp.supportsHttp3); // true with the shipped slice
print(NitroHttp.supportsBrotli);
print(NitroHttp.supportsZstd);
supportsHttp3 == false on a platform that should have it means the build fell
back to a system libcurl — worth catching early, because nothing else about it
looks wrong.
Building offline
Point NITRO_HTTP_DEPS_DIR at a directory of prebuilt slices and nothing
touches the network:
NITRO_HTTP_DEPS_DIR=/path/to/slices flutter build apk --release
Build those slices yourself with dart run nitro_http:build_curl — see
doc/ADVANCED.md. You only need this for
air-gapped or corporate-proxy machines; a normal build downloads them itself.
Quick start
import 'package:nitro_http/nitro_http.dart';
final client = NitroHttpClient(
settings: const ClientSettings(
baseUrl: 'https://api.example.com',
userAgent: 'my_app/1.0',
),
);
// GET some JSON
final user = await client.get('/users/42');
print((user.bodyToJson() as Map)['name']);
// POST some JSON
final created = await client.post('/users', body: HttpBody.json({'name': 'Ada'}));
print(created.statusCode); // 201
client.dispose(); // closes pooled connections
One client per API is the intended shape: it owns the connection pool, the cookie
jar and the cache, so reusing it is what makes the second request fast.
Features
Grouped by what you are trying to do. Every snippet below that calls this
library is compiled and run by
test/readme_examples_test.dart, so an API
change breaks that test before it can break a reader.
The default client
fetch() and every NitroHttp.* verb share one lazily created client. Configure
it once at startup and they all pick it up:
NitroHttp.init(
const ClientSettings(
baseUrl: 'https://api.example.com',
userAgent: 'my_app/1.0',
),
interceptors: [RetryInterceptor(maxRetries: 3)],
);
final user = await NitroHttp.get('/users/42'); // baseUrl applies
final posted = await NitroHttp.post('/users', body: HttpBody.json({'name': 'Ada'}));
Calling init again replaces the client and disposes the previous one, which
cancels anything still in flight on it. Call it during startup, not per screen.
Large bodies have a one-liner too, so you do not need a client just to stream a
download:
final report = await NitroHttp.getStream('/reports/2026.csv');
await for (final chunk in report.body) {
// chunk is a List<int>, delivered as it arrives
}
NitroHttp also carries the process-wide pieces — configureCache