HttpClient class

HTTP Client with SSE support and proper error handling

Constructors

HttpClient({required String baseUrl, Map<String, String>? defaultHeaders, Duration timeout = const Duration(seconds: 50), Client? client})

Properties

baseUrl String
final
defaultHeaders Map<String, String>
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
timeout Duration
final

Methods

close() → void
Close the client
delete<T>(String endpoint, {Map<String, String>? headers, Map<String, dynamic>? queryParameters, T dataParser(dynamic json)?}) Future<AppResponse<T>>
DELETE request
get<T>(String endpoint, {Map<String, String>? headers, Map<String, dynamic>? queryParameters, T dataParser(dynamic json)?}) Future<AppResponse<T>>
GET request
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch<T>(String endpoint, {Map<String, String>? headers, dynamic body, Map<String, dynamic>? queryParameters, T dataParser(dynamic json)?}) Future<AppResponse<T>>
PATCH request
post<T>(String endpoint, {Map<String, String>? headers, dynamic body, Map<String, dynamic>? queryParameters, T dataParser(dynamic json)?}) Future<AppResponse<T>>
POST request
put<T>(String endpoint, {Map<String, String>? headers, dynamic body, Map<String, dynamic>? queryParameters, T dataParser(dynamic json)?}) Future<AppResponse<T>>
PUT request
sse(String endpoint, {String method = 'GET', Map<String, String>? headers, dynamic body, Map<String, dynamic>? queryParameters, required void onChunk(String chunk), void onDone()?, void onError(Object error, StackTrace stackTrace)?}) Future<void>
Server-Sent Events (SSE) stream with callback Returns raw data as strings, not parsed through AppResponse Calls onChunk callback for each chunk received
sseStream(String endpoint, {String method = 'GET', Map<String, String>? headers, dynamic body, Map<String, dynamic>? queryParameters}) Stream<String>
Server-Sent Events (SSE) as stream Returns a Stream
toString() String
A string representation of this object.
inherited

Operators

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