http library
Sub-library entrypoint re-exporting the underlying http package.
Design Rationale
The main library (package:basic_http_interceptor/basic_http_interceptor.dart)
intentionally does not export package:http to avoid global namespace pollution.
package:http defines several top-level convenience functions (get, post,
put, delete, head, patch, read, readBytes) as well as ubiquitous
type names like Client, Request, and Response.
In standard Dart practices, importing package:http without a namespace prefix
can easily cause identifier collisions with local functions, state management
frameworks (e.g. GetX), or alternative networking/gRPC/Shelf libraries.
By providing this dedicated sub-library entrypoint, applications using
basic_http_interceptor can access raw http classes and functions on demand
without having to declare a direct dependency on http in their pubspec.yaml.
Recommended Usage
Import this sub-library with a namespace prefix (typically as http):
import 'package:basic_http_interceptor/http.dart' as http;
import 'package:basic_http_interceptor/basic_http_interceptor.dart';
Future<void> fetchData() async {
final http.Response response = await http.get(Uri.parse('https://api.example.com/data'));
if (response.statusCode == 200) {
print(response.body);
}
}
Classes
- Abortable
- An HTTP request that can be aborted before it completes.
- AbortableMultipartRequest
- A MultipartRequest which supports abortion using abortTrigger.
- AbortableRequest
- A Request which supports abortion using abortTrigger.
- AbortableStreamedRequest
- A StreamedRequest which supports abortion using abortTrigger.
- BaseClient
- The abstract base class for an HTTP client.
- BaseRequest
- The base class for HTTP requests.
- BaseResponse
- The base class for HTTP responses.
- BaseResponseWithUrl
- A BaseResponse with a url field.
- ByteStream
- A stream of chunks of bytes representing a single piece of data.
- Client
- The interface for HTTP clients that take care of maintaining persistent connections across multiple requests to the same server.
- MediaType
- A class representing an HTTP media type, as used in Accept and Content-Type headers.
- MultipartFile
- A file to be uploaded as part of a MultipartRequest.
- MultipartRequest
-
A
multipart/form-datarequest. - Request
- An HTTP request where the entire request body is known in advance.
- Response
- An HTTP response where the entire response body is known in advance.
- StreamedRequest
- An HTTP request where the request body is sent asynchronously after the connection has been established and the headers have been sent.
- StreamedResponse
- An HTTP response where the response body is received asynchronously after the headers have been received.
Extensions
Functions
-
delete(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> - Sends an HTTP DELETE request with the given headers to the given URL.
-
get(
Uri url, {Map< String, String> ? headers}) → Future<Response> - Sends an HTTP GET request with the given headers to the given URL.
-
head(
Uri url, {Map< String, String> ? headers}) → Future<Response> - Sends an HTTP HEAD request with the given headers to the given URL.
-
patch(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> - Sends an HTTP PATCH request with the given headers and body to the given URL.
-
post(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> - Sends an HTTP POST request with the given headers and body to the given URL.
-
put(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> - Sends an HTTP PUT request with the given headers and body to the given URL.
-
read(
Uri url, {Map< String, String> ? headers}) → Future<String> - Sends an HTTP GET request with the given headers to the given URL and returns a Future that completes to the body of the response as a String.
-
readBytes(
Uri url, {Map< String, String> ? headers}) → Future<Uint8List> - Sends an HTTP GET request with the given headers to the given URL and returns a Future that completes to the body of the response as a list of bytes.
-
runWithClient<
R> (R body(), Client clientFactory(), {ZoneSpecification? zoneSpecification}) → R -
Runs
bodyin its own Zone with the Client returned byclientFactoryset as the default Client.
Exceptions / Errors
- ClientException
- An exception caused by an error in a pkg/http client.
- RequestAbortedException
- Thrown when an HTTP request is aborted.