HttpTransport class abstract interface

The low-level HTTP client: it sends an HttpRequest over the network and gives back the response, without knowing about JSON, annotations or error handling.

It exists so that the clients built on it (Feign clients today) do not depend on how a platform does HTTP. Three implementations come with this package:

  • IoHttpTransport on dart:io (the VM, Flutter on mobile and desktop), from package:spring_web_dart/io.dart;
  • FetchHttpTransport on the browser's fetch, from package:spring_web_dart/browser.dart;
  • MockHttpTransport for tests, from package:spring_web_dart/testing.dart.

Most applications never call it. The Feign starter declares an httpTransport bean from platformHttpTransport and its clients use it. You implement this interface to put Feign on another HTTP library (Dio, package:http, a client with certificate pinning) and declare your implementation as a bean: the starter then uses it instead.

// A one-off call outside any Feign client.
final transport = platformHttpTransport();
try {
  final response = await transport.send(
    HttpRequest(
      method: HttpMethod.get,
      url: Uri.parse('https://api.neon.books/books/1'),
    ),
  );
  log.info(response.bodyText);
} finally {
  transport.close(); // Frees the pooled connections.
}

Spring (Java): ClientHttpRequestFactory, the layer under RestTemplate and RestClient:

ClientHttpRequestFactory factory = new JdkClientHttpRequestFactory();
ClientHttpResponse response =
    factory.createRequest(uri, HttpMethod.GET).execute();
Implementers

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → void
Releases the transport's connections. Call it when the transport is no longer needed (the Feign starter does when the application stops); do not use the transport afterwards.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(HttpRequest request) → Future<HttpResponse>
Sends request and reads the whole response into memory.
stream(HttpRequest request) → Future<StreamedHttpResponse>
Sends request and completes as soon as the status and headers have arrived. The body is then read from StreamedHttpResponse.body as it comes.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited