### Initialize rhttp Package Source: https://pub.dev/documentation/rhttp/latest/index.html Call `Rhttp.init()` once at the start of your application to initialize the rhttp package. This is a required setup step before making any HTTP requests. ```dart import 'package:rhttp/rhttp.dart'; void main() async { await Rhttp.init(); // add this runApp(MyApp()); } ``` -------------------------------- ### IoCompatibleClient get method implementation Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/get.html This snippet shows the implementation of the `get` method, which opens an HTTP connection using the GET method. It requires the host, port, and path of the server. ```dart @override Future get(String host, int port, String path) => open('GET', host, port, path); ``` -------------------------------- ### get Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient-class.html Opens an HTTP connection using the GET method. ```APIDOC ## get ### Description Opens an HTTP connection using the GET method. ### Method get ### Parameters - **host** (String) - The host to connect to. - **port** (int) - The port to connect to. - **path** (String) - The path of the request. ``` -------------------------------- ### afterResponse Implementation Example Source: https://pub.dev/documentation/rhttp/latest/rhttp/SimpleInterceptor/afterResponse.html An example of how the afterResponse method is implemented, showing how it can be used to chain interceptor logic. ```APIDOC ## afterResponse Implementation ### Description This implementation shows how the `afterResponse` method can be used to optionally call a custom handler (`_afterResponse`) or proceed with the next interceptor in the chain. ### Code Example ```dart @override Future> afterResponse( HttpResponse response, ) async { return await _afterResponse?.call(response) ?? Interceptor.next(response); } ``` ### Parameters - **response** (HttpResponse) - The HTTP response object received from the server. ``` -------------------------------- ### Make a Basic GET Request with rhttp Source: https://pub.dev/documentation/rhttp/latest/index.html Demonstrates how to make a simple GET request to a URL and access the status code and body of the response. Ensure `Rhttp.init()` has been called prior to this. ```dart import 'package:rhttp/rhttp.dart'; void main() async { await Rhttp.init(); // Make a GET request HttpTextResponse response = await Rhttp.get('https://example.com'); // Read the response int statusCode = response.statusCode; String body = response.body; } ``` -------------------------------- ### get method Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/get.html Opens an HTTP connection using the GET method. The server is specified using `host` and `port`, and the path (including a possible query) is specified using `path`. ```APIDOC ## get method ### Description Opens an HTTP connection using the GET method. The server is specified using `host` and `port`, and the path (including a possible query) is specified using `path`. ### Method GET ### Endpoint [host]:[port]/[path] ### Parameters #### Path Parameters - **host** (String) - Required - The hostname of the server. - **port** (int) - Required - The port of the server. - **path** (String) - Required - The path of the request, including any query parameters. ### Request Example ```dart // Example usage (assuming HttpClient is available) // final client = IoCompatibleClient(); // final request = await client.get('example.com', 80, '/resource?query=test'); ``` ### Response #### Success Response (HttpClientRequest) Returns an `HttpClientRequest` object that can be used to send the request and receive the response. ``` -------------------------------- ### Setting the keyLog Callback Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/keyLog.html This example demonstrates how to set the keyLog callback to append TLS key log lines to a file. This allows for decryption of network traffic using tools like Wireshark. ```APIDOC ## set keyLog ### Description Sets a callback that will be called when new TLS keys are exchanged with the server. It will receive one line of text in NSS Key Log Format for each call. Writing these lines to a file will allow tools (such as Wireshark) to decrypt communication between the this client and the server. This is meant to allow network-level debugging of secure sockets and should not be used in production code. ### Method Signature `set keyLog (dynamic callback(String line)?)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```dart final log = File('keylog.txt'); final client = HttpClient(); client.keyLog = (line) => log.writeAsStringSync(line, mode: FileMode.append); ``` ### Response This is a setter method and does not return a value directly. The callback function provided will be executed when TLS keys are exchanged. #### Success Response N/A #### Response Example N/A ``` -------------------------------- ### Implement getUrl using openUrl Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/getUrl.html This snippet shows the implementation of the getUrl method, which calls openUrl with the 'GET' method and the provided URL. It's used to initiate an HTTP GET request. ```dart @override Future getUrl(Uri url) => openUrl('GET', url); ``` -------------------------------- ### Setting a custom connectionFactory Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/connectionFactory.html This example demonstrates how to set a custom connectionFactory to use a Unix domain socket for connections, bypassing standard network protocols. It also sets findProxy to 'DIRECT' to ensure no proxy is used. ```APIDOC ## set connectionFactory ### Description Sets the function used to create socket connections. The URL requested and proxy configuration are passed as arguments. `proxyHost` and `proxyPort` will be `null` if the connection is not made through a proxy. It's important that the function correctly handles `proxyHost` and `proxyPort` if they are not `null`. ### Method ```dart set connectionFactory (Future> Function(Uri url, String? proxyHost, int? proxyPort)?) f ``` ### Parameters - **f** (Future> Function(Uri url, String? proxyHost, int? proxyPort)?) - The function to create socket connections. - **url** (Uri) - The URL being requested. - **proxyHost** (String?) - The proxy host, or null if not using a proxy. - **proxyPort** (int?) - The proxy port, or null if not using a proxy. ### Request Example ```dart import "dart:io"; void main() async { HttpClient client = HttpClient() ..connectionFactory = (Uri uri, String? proxyHost, int? proxyPort) { assert(proxyHost == null); assert(proxyPort == null); var address = InternetAddress("/var/run/docker.sock", type: InternetAddressType.unix); return Socket.startConnect(address, 0); } ..findProxy = (Uri uri) => 'DIRECT'; final request = await client.getUrl(Uri.parse("http://ignored/v1.41/info")); final response = await request.close(); print(response.statusCode); await response.drain(); client.close(); } ``` ### Response This property is a setter and does not return a value directly. The effect is on how subsequent connections are established. ``` -------------------------------- ### IoCompatibleClient.createSync Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/IoCompatibleClient.createSync.html Creates a new HTTP client synchronously. Use this method if your app is starting up to simplify the code that might arise by using async/await. Note: This method crashes when configured to use HTTP/3. ```APIDOC ## IoCompatibleClient.createSync ### Description Creates a new HTTP client synchronously. Use this method if your app is starting up to simplify the code that might arise by using async/await. Note: This method crashes when configured to use HTTP/3. See: https://codeberg.org/Tienisto/rhttp/issues/10 ### Parameters #### Named Parameters - **settings** (ClientSettings?) - Optional - Settings for the client. - **interceptors** (List?) - Optional - A list of interceptors to apply to the client. ### Implementation ```dart factory IoCompatibleClient.createSync({ ClientSettings? settings, List? interceptors, }) { final rhttpClient = RhttpClient.createSync( settings: (settings ?? const ClientSettings()), interceptors: interceptors, ); return IoCompatibleClient._(rhttpClient); } ``` ``` -------------------------------- ### get method Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpCompatibleClient/get.html Sends an HTTP GET request with the given headers to the given URL. For more fine-grained control over the request, use send instead. ```APIDOC ## get ### Description Sends an HTTP GET request with the given headers to the given URL. For more fine-grained control over the request, use send instead. ### Method GET ### Endpoint [URL] ### Parameters #### Path Parameters - **url** (Uri) - Required - The URL to send the GET request to. #### Query Parameters None #### Request Body None ### Request Example ```dart // Example usage: await client.get(Uri.parse('https://example.com')); ``` ### Response #### Success Response (200) - **Response** - The HTTP response object. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### read Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpCompatibleClient-class.html Sends an HTTP GET request and returns the response body as a String. ```APIDOC ## read ### Description 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. ### Method GET ### Endpoint [URL] ### Parameters #### Path Parameters - **url** (Uri) - Required - The URI to send the request to. #### Named Parameters - **headers** (Map?) - Optional - Headers to include in the request. ### Returns - **Future** - A Future that completes with the response body as a String. ``` -------------------------------- ### RhttpCompatibleClient.createSync Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpCompatibleClient/RhttpCompatibleClient.createSync.html Creates a new HTTP client synchronously. Use this method if your app is starting up to simplify the code that might arise by using async/await. Note: This method crashes when configured to use HTTP/3. ```APIDOC ## RhttpCompatibleClient.createSync ### Description Creates a new HTTP client synchronously. Use this method if your app is starting up to simplify the code that might arise by using async/await. Note: This method crashes when configured to use HTTP/3. See: https://codeberg.org/Tienisto/rhttp/issues/10 ### Parameters #### Named Parameters - **settings** (ClientSettings?) - Optional - Settings for the client. - **interceptors** (List?) - Optional - A list of interceptors to apply to the client. ### Implementation ```dart factory RhttpCompatibleClient.createSync({ ClientSettings? settings, List? interceptors, }) { final client = RhttpClient.createSync( settings: (settings ?? const ClientSettings()).digest(), interceptors: interceptors, ); return RhttpCompatibleClient.of(client); } ``` ``` -------------------------------- ### StaticProxy.all Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/StaticProxy/StaticProxy.all.html The StaticProxy.all constructor takes a URL as a parameter and initializes the proxy to apply to all requests. ```APIDOC ## StaticProxy.all Constructor ### Description Initializes a StaticProxy instance that will proxy all requests to the specified URL. ### Parameters #### Path Parameters - **url** (String) - Required - The base URL for the proxy. ### Implementation ```dart const StaticProxy.all(String url) : this(url: url, condition: ProxyCondition.all); ``` ``` -------------------------------- ### ClientSettings Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/ClientSettings-class.html Initializes a new instance of the ClientSettings class with customizable options. ```APIDOC ## ClientSettings Constructor ### Description Initializes a new instance of the ClientSettings class. ### Parameters - **baseUrl** (String?) - Optional - Base URL to be prefixed to all requests. - **cookieSettings** (CookieSettings?) - Optional - Configuration options for cookie handling. - **httpVersionPref** (HttpVersionPref) - Optional - The preferred HTTP version to use. Defaults to HttpVersionPref.all. - **timeoutSettings** (TimeoutSettings?) - Optional - Timeout and keep alive settings. - **throwOnStatusCode** (bool) - Optional - Throws an exception if the status code is 4xx or 5xx. Defaults to true. - **proxySettings** (ProxySettings?) - Optional - Proxy settings. - **redirectSettings** (RedirectSettings?) - Optional - Redirect settings. By default, the client will follow maximum 10 redirects. - **tlsSettings** (TlsSettings?) - Optional - TLS settings. - **dnsSettings** (DnsSettings?) - Optional - DNS settings and resolver overrides. - **userAgent** (String?) - Optional - A convenient way to set the User-Agent header. By default, there is no User-Agent header. ``` -------------------------------- ### Define HttpMethod GET Constant Source: https://pub.dev/documentation/rhttp/latest/rhttp/HttpMethod/get-constant.html This snippet shows the implementation of the static const get, which is an instance of HttpMethod representing the GET request. ```dart static const get = HttpMethod('GET'); ``` -------------------------------- ### ProxySettings.list Source: https://pub.dev/documentation/rhttp/latest/rhttp/ProxySettings-class.html Initializes ProxySettings with a list of custom proxies. ```APIDOC ## ProxySettings.list ### Description Use a list of custom proxies. ### Factory `ProxySettings.list(List proxies)` ``` -------------------------------- ### RhttpCompatibleClient get method implementation Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpCompatibleClient/get.html This is the implementation of the get method in RhttpCompatibleClient. It sends an unstreamed GET request to the specified URL with optional headers. ```dart @override Future get(Uri url, {Map? headers}) => _sendUnstreamed('GET', url, headers); ``` -------------------------------- ### ClientSettings.copyWith Source: https://pub.dev/documentation/rhttp/latest/rhttp/ClientSettings-class.html Creates a new ClientSettings instance by copying existing settings and applying optional overrides. ```APIDOC ## ClientSettings.copyWith ### Description Creates a new ClientSettings instance by copying existing settings and applying optional overrides. ### Parameters - **baseUrl** (String?) - Optional - Base URL to be prefixed to all requests. - **cookieSettings** (CookieSettings?) - Optional - Configuration options for cookie handling. - **httpVersionPref** (HttpVersionPref?) - Optional - The preferred HTTP version to use. - **timeoutSettings** (TimeoutSettings?) - Optional - Timeout and keep alive settings. - **throwOnStatusCode** (bool?) - Optional - Throws an exception if the status code is 4xx or 5xx. - **proxySettings** (ProxySettings?) - Optional - Proxy settings. - **redirectSettings** (RedirectSettings?) - Optional - Redirect settings. - **tlsSettings** (TlsSettings?) - Optional - TLS settings. - **dnsSettings** (DnsSettings?) - Optional - DNS settings and resolver overrides. - **userAgent** (String?) - Optional - A convenient way to set the User-Agent header. ### Returns - ClientSettings - A new ClientSettings instance with updated values. ``` -------------------------------- ### IoCompatibleClient.createSync Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/IoCompatibleClient.createSync.html Creates a new HTTP client synchronously. Use this method if your app is starting up to simplify the code that might arise by using async/await. This method crashes when configured to use HTTP/3. ```dart factory IoCompatibleClient.createSync({ ClientSettings? settings, List? interceptors, }) { final rhttpClient = RhttpClient.createSync( settings: (settings ?? const ClientSettings()), interceptors: interceptors, ); return IoCompatibleClient._(rhttpClient); } ``` -------------------------------- ### ProxySettings.list Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/ProxySettings/ProxySettings.list.html Initializes ProxySettings with a provided list of custom proxies. ```APIDOC ## ProxySettings.list Constructor ### Description Use a list of custom proxies to configure proxy settings. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature ```dart const ProxySettings.list(List proxies) ``` ### Implementation ```dart const factory ProxySettings.list(List proxies) = CustomProxyList; ``` ### Example ```dart final proxySettings = ProxySettings.list([CustomProxy(host: '127.0.0.1', port: 8080)]); ``` ``` -------------------------------- ### Rhttp Get Method Implementation Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpClient/get.html This is the implementation of the get method, which is an alias for requestText with the HttpMethod set to GET. It accepts URL, query parameters, headers, and cancellation tokens. ```dart Future get( String url, { Map? query, List<(String, String)>? queryRaw, HttpHeaders? headers, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, }) => requestText( method: HttpMethod.get, url: url, query: query, queryRaw: queryRaw, headers: headers, cancelToken: cancelToken, onReceiveProgress: onReceiveProgress, ); ``` -------------------------------- ### Rhttp Get Method Implementation Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/get.html Shows the implementation of the static get method, which internally calls the requestText method with HttpMethod.get. This provides a streamlined way to perform GET requests. ```dart static Future get( String url, { ClientSettings? settings, List? interceptors, Map? query, List<(String, String)>? queryRaw, HttpHeaders? headers, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, }) => requestText( settings: settings, interceptors: interceptors, method: HttpMethod.get, url: url, query: query, queryRaw: queryRaw, headers: headers, cancelToken: cancelToken, onReceiveProgress: onReceiveProgress, ); ``` -------------------------------- ### RedirectSettings.limited Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/RedirectSettings/RedirectSettings.limited.html Initializes RedirectSettings with a limit on the number of redirects. ```APIDOC ## RedirectSettings.limited Constructor ### Description Limits the number of redirects. ### Parameters #### Path Parameters - **maxRedirects** (int) - Required - The maximum number of redirects allowed. ``` -------------------------------- ### get Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpCompatibleClient-class.html Sends an HTTP GET request to the specified URI with optional headers. ```APIDOC ## get ### Description Sends an HTTP GET request with the given headers to the given URL. ### Method GET ### Endpoint [URL] ### Parameters #### Path Parameters - **url** (Uri) - Required - The URI to send the request to. #### Named Parameters - **headers** (Map?) - Optional - Headers to include in the request. ``` -------------------------------- ### init static method Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/init.html Initializes the Rust library. This method should be called once before using other Rhttp functionalities. ```APIDOC ## init static method ### Description Initializes the Rust library. ### Signature ```dart Future init() ``` ### Implementation ```dart static Future init() async { await RustLib.init( // Reduce the probably of dependency hell. // Projects using rhttp may use frb for other purposes as well. forceSameCodegenVersion: false, ); } ``` ``` -------------------------------- ### get Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpClient-class.html Alias for getText. Makes an HTTP GET request and returns the response as text. ```APIDOC ## GET (getText alias) ### Description Makes an HTTP GET request and returns the response as text. ### Method GET ### Endpoint [url] ### Parameters #### Query Parameters - **query** (Map?) - Optional - Query parameters for the request. - **queryRaw** (List<(String, String)>?) - Optional - Raw query parameters for the request. #### Headers - **headers** (HttpHeaders?) - Optional - Custom HTTP headers. #### Other Parameters - **cancelToken** (CancelToken?) - Optional - Token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - Callback for receive progress. ### Response #### Success Response (200) - **HttpTextResponse** - The response as text. ``` -------------------------------- ### HTTP GET Request (Stream) Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp-class.html Makes an HTTP GET request and returns the response as a stream. ```APIDOC ## GET (Stream) ### Description Makes an HTTP GET request and returns the response as a stream. ### Method GET ### Endpoint [url] ### Parameters #### Query Parameters - **query** (Map) - Optional - Query parameters to include in the URL. - **queryRaw** (List<(String, String)>) - Optional - Raw query parameters to include in the URL. #### Headers - **headers** (HttpHeaders) - Optional - Custom HTTP headers. #### Other Parameters - **settings** (ClientSettings?) - Optional - Client settings for the request. - **interceptors** (List?) - Optional - Interceptors to apply to the request. - **cancelToken** (CancelToken?) - Optional - Token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - Callback for receive progress. ### Response #### Success Response (200) - **HttpStreamResponse** - The response body as a stream. ``` -------------------------------- ### create Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient-class.html Creates a new HTTP client asynchronously. Use this method if your app is already running to avoid blocking the UI. ```APIDOC ## create ### Description Creates a new HTTP client asynchronously. Use this method if your app is already running to avoid blocking the UI. ### Method static create ### Parameters #### Named Parameters - **settings** (ClientSettings?) - Optional - Settings for the client. - **interceptors** (List?) - Optional - A list of interceptors to apply to requests. ``` -------------------------------- ### HTTP GET Request (Bytes) Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp-class.html Makes an HTTP GET request and returns the response as bytes. ```APIDOC ## GET (Bytes) ### Description Makes an HTTP GET request and returns the response as bytes. ### Method GET ### Endpoint [url] ### Parameters #### Query Parameters - **query** (Map) - Optional - Query parameters to include in the URL. - **queryRaw** (List<(String, String)>) - Optional - Raw query parameters to include in the URL. #### Headers - **headers** (HttpHeaders) - Optional - Custom HTTP headers. #### Other Parameters - **settings** (ClientSettings?) - Optional - Client settings for the request. - **interceptors** (List?) - Optional - Interceptors to apply to the request. - **cancelToken** (CancelToken?) - Optional - Token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - Callback for receive progress. ### Response #### Success Response (200) - **HttpBytesResponse** - The response body as bytes. ``` -------------------------------- ### ClientCertificate Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/ClientCertificate-class.html Initializes a new ClientCertificate instance with the provided certificate and private key. ```APIDOC ## ClientCertificate Constructor ### Description Creates a new `ClientCertificate` object. ### Parameters #### Path Parameters - **certificate** (String) - Required - The certificate in PEM format. - **privateKey** (String) - Required - The private key in PEM format. ``` -------------------------------- ### Constructors Source: https://pub.dev/documentation/rhttp/latest/rhttp/HttpHeaders-class.html Initialize HttpHeaders instances using different methods: a list of string tuples, a typed map with predefined keys, or a raw string-to-string map. ```APIDOC ## HttpHeaders.list ### Description A raw header list. This allows for multiple headers with the same name. ### Parameters - **list** (List<(String, String)>) - A list of header name-value pairs. ### Factory `const factory HttpHeaders.list(List<(String, String)> list)` ``` ```APIDOC ## HttpHeaders.map ### Description A typed header map with a set of predefined keys. ### Parameters - **map** (Map) - A map where keys are HttpHeaderName and values are header strings. ### Factory `const factory HttpHeaders.map(Map map)` ``` ```APIDOC ## HttpHeaders.rawMap ### Description A raw header map where the keys are strings. ### Parameters - **map** (Map) - A map where both keys and values are header strings. ### Factory `const factory HttpHeaders.rawMap(Map map)` ``` -------------------------------- ### Rhttp Get Method Signature Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/get.html Defines the signature of the static get method, outlining its parameters for making HTTP GET requests. It accepts a URL and optional settings, interceptors, query parameters, headers, and cancellation tokens. ```dart static Future get( String url, { ClientSettings? settings, List? interceptors, Map? query, List<(String, String)>? queryRaw, HttpHeaders? headers, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, }) ``` -------------------------------- ### StaticProxy.all Constructor Implementation Source: https://pub.dev/documentation/rhttp/latest/rhttp/StaticProxy/StaticProxy.all.html This is the implementation of the StaticProxy.all constructor. It initializes the proxy with a given URL and sets the condition to ProxyCondition.all. ```dart const StaticProxy.all(String url) : this(url: url, condition: ProxyCondition.all); ``` -------------------------------- ### RhttpClient Get Method Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpClient/get.html The get method is an alias for getText and is used to make HTTP GET requests. It supports optional query parameters, raw query parameters, custom headers, cancellation tokens, and progress callbacks for received data. ```APIDOC ## get(String url, {Map? query, List<(String, String)>? queryRaw, HttpHeaders? headers, CancelToken? cancelToken, ProgressCallback? onReceiveProgress}) ### Description Alias for getText. Makes an HTTP GET request to the specified URL. ### Method GET ### Endpoint [URL provided as argument] ### Parameters #### Path Parameters None #### Query Parameters - **query** (Map?) - Optional - A map of key-value pairs for query parameters. - **queryRaw** (List<(String, String)>?) - Optional - A list of raw query parameter tuples. #### Headers - **headers** (HttpHeaders?) - Optional - Custom HTTP headers to include in the request. #### Other Parameters - **cancelToken** (CancelToken?) - Optional - A token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - A callback function to track download progress. ``` -------------------------------- ### StaticProxy Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/StaticProxy/StaticProxy.html Initializes a new StaticProxy instance with a required URL and a ProxyCondition. ```APIDOC ## StaticProxy Constructor ### Description Creates a new StaticProxy with a given URL and condition. ### Parameters #### Path Parameters - **url** (String) - Required - The URL for the proxy. - **condition** (ProxyCondition) - Required - The condition under which the proxy should be used. ### Implementation ```dart const StaticProxy({ required this.url, required this.condition, }) : super._(); ``` ``` -------------------------------- ### getText static method Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/getText.html Makes an HTTP GET request and returns the response as text. This method is a convenient wrapper for performing text-based GET requests with customizable options. ```APIDOC ## getText static method ### Description Makes an HTTP GET request and returns the response as text. ### Method GET ### Endpoint [URL provided by the 'url' parameter] ### Parameters #### Path Parameters None #### Query Parameters - **query** (Map) - Optional - A map of query parameters to append to the URL. - **queryRaw** (List<(String, String)>) - Optional - A list of raw query parameter tuples to append to the URL. #### Request Body None ### Headers - **headers** (HttpHeaders) - Optional - Custom HTTP headers to include in the request. ### Other Options - **settings** (ClientSettings?) - Optional - Client-specific settings for the request. - **interceptors** (List?) - Optional - A list of interceptors to apply to the request. - **cancelToken** (CancelToken?) - Optional - A token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - A callback function to track progress of the response reception. ### Response #### Success Response (200) - **HttpTextResponse** - The HTTP response object containing the response body as text. ``` -------------------------------- ### create static method Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/create.html Creates a new HTTP client asynchronously. Use this method if your app is already running to avoid blocking the UI. ```APIDOC ## create static method ### Description Creates a new HTTP client asynchronously. Use this method if your app is already running to avoid blocking the UI. ### Method Signature `Future create({ ClientSettings? settings, List? interceptors })` ### Parameters #### Optional Parameters - **settings** (`ClientSettings?`) - Configuration settings for the client. - **interceptors** (`List?`) - A list of interceptors to be applied to the client. ### Implementation Example ```dart static Future create({ ClientSettings? settings, List? interceptors, }) async { final rhttpClient = await RhttpClient.create( settings: (settings ?? const ClientSettings()), interceptors: interceptors, ); return IoCompatibleClient._(rhttpClient); } ``` ``` -------------------------------- ### Implement RhttpCompatibleClient read method Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpCompatibleClient/read.html This method sends an HTTP GET request and checks for success before returning the response body. Use this for simple GET requests where only the body is needed. ```dart @override Future read(Uri url, {Map? headers}) async { final response = await get(url, headers: headers); _checkResponseSuccess(url, response); return response.body; } ``` -------------------------------- ### IoCompatibleClient post method implementation Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/post.html This is the implementation of the post method. It opens an HTTP connection using the POST method, specifying the server via host and port, and the path including any query parameters. ```dart @override Future post(String host, int port, String path) => open('POST', host, port, path); ``` -------------------------------- ### Initialize Rhttp Rust Library Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/init.html Call this static method to initialize the Rust library. It uses `forceSameCodegenVersion: false` to reduce the probability of dependency hell. ```dart static Future init() async { await RustLib.init( // Reduce the probably of dependency hell. // Projects using rhttp may use frb for other purposes as well. forceSameCodegenVersion: false, ); } ``` -------------------------------- ### state Property Source: https://pub.dev/documentation/rhttp/latest/rhttp/CancelToken-class.html Gets the current state of the CancelToken. ```APIDOC ## Properties ### state → CancelState The current state of the token. **Example:** ```dart print('Token state: ${cancelToken.state}'); ``` ``` -------------------------------- ### getUrl Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient-class.html Opens an HTTP connection using the GET method. ```APIDOC ## getUrl ### Description Opens an HTTP connection using the GET method. ### Method getUrl ### Parameters - **url** (Uri) - The URL to connect to. ``` -------------------------------- ### ProxySettings.static Source: https://pub.dev/documentation/rhttp/latest/rhttp/ProxySettings-class.html Sets up a static proxy that applies only to requests matching specific conditions. ```APIDOC ## ProxySettings.static ### Description Use a single static proxy for specific requests. ### Factory `ProxySettings.static({required String url, required ProxyCondition condition})` ``` -------------------------------- ### Initialize Rhttp Library Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp-class.html Initializes the Rust library for Rhttp operations. ```APIDOC ## init() ### Description Initializes the Rust library. ### Method Static method call ### Parameters None ### Response #### Success Response (void) - **void** - Indicates successful initialization. ``` -------------------------------- ### HttpMethod.get Source: https://pub.dev/documentation/rhttp/latest/rhttp/HttpMethod/get-constant.html Represents the HTTP GET method. This is a predefined constant for convenience. ```APIDOC ## HttpMethod.get ### Description Provides a constant for the HTTP GET method. ### Method GET ### Endpoint N/A (This is a constant definition, not an endpoint) ### Implementation ```dart static const get = HttpMethod('GET'); ``` ``` -------------------------------- ### ProxySettings.proxy Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/ProxySettings/ProxySettings.proxy.html Initializes ProxySettings with a single proxy URL to be used for all requests. ```APIDOC ## ProxySettings.proxy Constructor ### Description Use a single proxy for all requests. Example: `ProxySettings.proxy('http://localhost:8080')` ### Method Signature `const ProxySettings.proxy(String url)` ### Parameters #### Path Parameters - **url** (String) - Required - The URL of the proxy server. ``` -------------------------------- ### Implement HTTP GET Request with getText Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/getText.html This implementation shows how the getText static method is defined, delegating the request to a more general `requestText` function with the HTTP method set to GET. It accepts optional parameters for client settings, interceptors, query parameters, headers, cancellation, and progress callbacks. ```dart static Future getText( String url, { ClientSettings? settings, List? interceptors, Map? query, List<(String, String)>? queryRaw, HttpHeaders? headers, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, }) => requestText( settings: settings, interceptors: interceptors, method: HttpMethod.get, url: url, query: query, queryRaw: queryRaw, headers: headers, cancelToken: cancelToken, onReceiveProgress: onReceiveProgress, ); ``` -------------------------------- ### BaseHttpRequest Constructor Source: https://pub.dev/documentation/rhttp/latest/rhttp/BaseHttpRequest/BaseHttpRequest.html Initializes a new BaseHttpRequest with specified HTTP method, URL, query parameters, headers, body, and other options. ```APIDOC ## BaseHttpRequest Constructor ### Description Initializes a new BaseHttpRequest object. ### Parameters - **method** (HttpMethod) - Optional - The HTTP method to use (defaults to HttpMethod.get). - **url** (String) - Required - The URL for the request. - **query** (Map) - Optional - Query parameters for the URL. - **queryRaw** (List<(String, String)>) - Optional - Raw query parameters for the URL. - **headers** (HttpHeaders) - Optional - Custom headers for the request. - **body** (HttpBody) - Optional - The request body. - **expectBody** (HttpExpectBody) - Optional - Specifies how the response body should be expected (defaults to HttpExpectBody.stream). - **cancelToken** (CancelToken) - Optional - A token to cancel the request. - **onSendProgress** (ProgressCallback) - Optional - Callback for send progress. - **onReceiveProgress** (ProgressCallback) - Optional - Callback for receive progress. ### Notes - Cannot specify both `query` and `queryRaw` parameters simultaneously. ``` -------------------------------- ### getText Method Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpClient/getText.html Makes an HTTP GET request and returns the response as text. ```APIDOC ## getText(url, query, queryRaw, headers, cancelToken, onReceiveProgress) ### Description Makes an HTTP GET request and returns the response as text. ### Method GET ### Endpoint [URL provided by the 'url' parameter] ### Parameters #### Path Parameters None #### Query Parameters - **query** (Map?) - Optional - Query parameters to be appended to the URL. - **queryRaw** (List<(String, String)>?) - Optional - Raw query parameters to be appended to the URL. #### Headers - **headers** (HttpHeaders?) - Optional - Custom HTTP headers to be sent with the request. #### Other Parameters - **cancelToken** (CancelToken?) - Optional - A token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - A callback function to track the progress of receiving the response. ### Request Example ```dart // Example usage: var response = await httpClient.getText( 'https://example.com/data', query: {'param1': 'value1'}, headers: {'X-Custom-Header': 'value'}, ); ``` ### Response #### Success Response (200) - **HttpTextResponse** - The response body as text. ``` -------------------------------- ### Implement HEAD Request with IoCompatibleClient Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/head.html This snippet shows the implementation of the head method, which opens an HTTP connection using the HEAD method. It requires the host, port, and path of the server. The method delegates the actual connection opening to the 'open' method. ```dart @override Future head(String host, int port, String path) => open('HEAD', host, port, path); ``` -------------------------------- ### readBytes Source: https://pub.dev/documentation/rhttp/latest/rhttp/RhttpCompatibleClient-class.html Sends an HTTP GET request and returns the response body as a list of bytes. ```APIDOC ## readBytes ### Description 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. ### Method GET ### Endpoint [URL] ### Parameters #### Path Parameters - **url** (Uri) - Required - The URI to send the request to. #### Named Parameters - **headers** (Map?) - Optional - Headers to include in the request. ### Returns - **Future** - A Future that completes with the response body as a list of bytes. ``` -------------------------------- ### getBytes static method Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/getBytes.html Makes an HTTP GET request and returns the response as bytes. ```APIDOC ## getBytes static method ### Description Makes an HTTP GET request and returns the response as bytes. ### Method Signature Future getBytes( String url, { ClientSettings? settings, List? interceptors, Map? query, List<(String, String)>? queryRaw, HttpHeaders? headers, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, } ) ### Parameters #### Path Parameters - None #### Query Parameters - **query** (Map) - Optional - A map of query parameters to append to the URL. - **queryRaw** (List<(String, String)>) - Optional - A list of raw query parameter tuples to append to the URL. #### Request Body - None ### Headers - **headers** (HttpHeaders) - Optional - Custom HTTP headers to include in the request. ### Other Options - **settings** (ClientSettings) - Optional - Client-specific settings. - **interceptors** (List) - Optional - A list of interceptors to apply to the request. - **cancelToken** (CancelToken) - Optional - A token to cancel the request. - **onReceiveProgress** (ProgressCallback) - Optional - A callback function to track download progress. ### Response #### Success Response - Returns a `Future` containing the response body as bytes. ``` -------------------------------- ### open method Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/open.html Opens an HTTP connection. The HTTP method, server host and port, and path are specified as arguments. The Host header is automatically set. ```APIDOC ## open method ### Description Opens an HTTP connection. The HTTP method to use is specified in `method`, the server is specified using `host` and `port`, and the path (including a possible query) is specified using `path`. The path may also contain a URI fragment, which will be ignored. The `Host` header for the request will be set to the value `host`:`port` (if `host` is an IP address, it will still be used in the `Host` header). This can be overridden through the HttpClientRequest interface before the request is sent. ### Method Signature ```dart Future open( String method, String host, int port, String path, ) ``` ### Parameters #### Path Parameters - **method** (String) - The HTTP method to use (e.g., 'GET', 'POST'). - **host** (String) - The server host address. - **port** (int) - The server port. - **path** (String) - The path for the request, including any query parameters. ### Implementation ```dart @override Future open( String method, String host, int port, String path, ) => openUrl(method, Uri.parse('http://$host:$port$path')); ``` ``` -------------------------------- ### getStream static method Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/getStream.html Makes an HTTP GET request and returns the response as a stream. ```APIDOC ## getStream static method ### Description Makes an HTTP GET request and returns the response as a stream. ### Method GET ### Endpoint [URL provided by the 'url' parameter] ### Parameters #### Path Parameters None #### Query Parameters - **query** (Map) - Optional - A map of query parameters. - **queryRaw** (List<(String, String)>) - Optional - A list of raw query parameters. #### Request Body None ### Request Example ```dart // Example usage: await Rhttp.getStream('https://example.com/data'); ``` ### Response #### Success Response (200) - **HttpStreamResponse** - The response body as a stream. #### Response Example ```dart // Assuming a successful response: final responseStream = await Rhttp.getStream('https://example.com/large_file'); responseStream.stream.listen((data) { // Process data chunks }); ``` ### Additional Options - **settings** (ClientSettings?) - Optional - Client settings for the request. - **interceptors** (List?) - Optional - A list of interceptors to apply. - **headers** (HttpHeaders?) - Optional - Custom HTTP headers. - **cancelToken** (CancelToken?) - Optional - A token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - A callback for receiving progress updates. ``` -------------------------------- ### Get idleTimeout Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/idleTimeout.html Retrieves the current idle timeout duration for non-active persistent connections. ```APIDOC ## Get idleTimeout ### Description Gets the idle timeout of non-active persistent (keep-alive) connections. The default value is 15 seconds. ### Implementation ```dart @override Duration get idleTimeout => client.settings.timeoutSettings?.keepAliveTimeout ?? Duration.zero; ``` ``` -------------------------------- ### Create HTTP Client Synchronously Source: https://pub.dev/documentation/rhttp/latest/index.html Use RhttpClient.createSync for synchronous client creation. This method should only be called during application startup to prevent blocking the UI thread. ```dart final client = RhttpClient.createSync(); ``` -------------------------------- ### post method Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/post.html Opens an HTTP connection using the POST method. The server is specified using `host` and `port`, and the path (including a possible query) is specified using `path`. ```APIDOC ## POST post ### Description Opens an HTTP connection using the POST method. The server is specified using `host` and `port`, and the path (including a possible query) is specified using `path`. ### Method POST ### Endpoint [host]:[port]/[path] ### Parameters #### Path Parameters - **host** (String) - Required - The hostname or IP address of the server. - **port** (int) - Required - The port number of the server. - **path** (String) - Required - The path of the resource, including any query parameters. ### Request Example ```dart // Example usage (assuming HttpClient is available) var client = IoCompatibleClient(); var request = await client.post('example.com', 8080, '/api/data?id=123'); ``` ### Response #### Success Response (HttpClientRequest) Returns an `HttpClientRequest` object that can be used to send data to the server. #### Response Example ```dart // The actual response object will be an HttpClientRequest // Example of how you might use it: // request.write('Some data'); // await request.close(); ``` ``` -------------------------------- ### connectionTimeout Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient-class.html Gets and sets the connection timeout duration. This specifies the maximum time to wait for a connection to be established. ```APIDOC ## connectionTimeout ### Description Gets and sets the connection timeout. ### Property connectionTimeout ↔ Duration? ``` -------------------------------- ### IoCompatibleClient.createSync Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient-class.html Creates a new HTTP client synchronously. This is useful during application startup to simplify code that might otherwise require async/await. ```APIDOC ## IoCompatibleClient.createSync ### Description Creates a new HTTP client synchronously. Use this method if your app is starting up to simplify the code that might arise by using async/await. ### Factory IoCompatibleClient.createSync({ClientSettings? settings, List? interceptors}) ``` -------------------------------- ### Get Idle Timeout Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient/idleTimeout.html Retrieves the current idle timeout for keep-alive connections. Returns Duration.zero if not configured. ```dart @override Duration get idleTimeout => client.settings.timeoutSettings?.keepAliveTimeout ?? Duration.zero; ``` -------------------------------- ### open Source: https://pub.dev/documentation/rhttp/latest/rhttp/IoCompatibleClient-class.html Opens an HTTP connection. ```APIDOC ## open ### Description Opens an HTTP connection. ### Method open ### Parameters - **method** (String) - The HTTP method to use. - **host** (String) - The host to connect to. - **port** (int) - The port to connect to. - **path** (String) - The path of the request. ``` -------------------------------- ### Get CancelToken State Source: https://pub.dev/documentation/rhttp/latest/rhttp/CancelToken/state.html Access the current state of the CancelToken. This property returns a CancelState enum value. ```dart CancelState get state => _state; ``` -------------------------------- ### StaticProxy Constructors Source: https://pub.dev/documentation/rhttp/latest/rhttp/StaticProxy-class.html Constructors for creating StaticProxy instances with different configurations. ```APIDOC ## StaticProxy Constructors ### StaticProxy({required String url, required ProxyCondition condition}) Creates a StaticProxy with a specific URL and condition. ### StaticProxy.all(String url) Creates a StaticProxy for all requests using the given URL. ### StaticProxy.http(String url) Creates a StaticProxy specifically for HTTP requests using the given URL. ### StaticProxy.https(String url) Creates a StaticProxy specifically for HTTPS requests using the given URL. ``` -------------------------------- ### Rhttp.get Source: https://pub.dev/documentation/rhttp/latest/rhttp/Rhttp/get.html Makes an HTTP GET request to the specified URL. This is an alias for getText and internally calls requestText with HttpMethod.get. ```APIDOC ## Rhttp.get ### Description Makes an HTTP GET request to the specified URL. This method is an alias for `getText` and internally calls `requestText` with `HttpMethod.get`. ### Method GET ### Endpoint Not applicable (this is an SDK method, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters - **query** (Map?) - Optional - Query parameters to be appended to the URL. - **queryRaw** (List<(String, String)>?) - Optional - Raw query parameters to be appended to the URL. #### Request Body None ### Request Example ```dart // Example usage: await Rhttp.get('https://example.com/api/data', query: {'id': '123'}); ``` ### Response #### Success Response (200) - **HttpTextResponse** - The response from the server as text. #### Response Example ```json { "data": "some text response" } ``` ### Parameters Details - **url** (String) - Required - The URL to send the GET request to. - **settings** (ClientSettings?) - Optional - Client settings for the request. - **interceptors** (List?) - Optional - A list of interceptors to apply to the request. - **headers** (HttpHeaders?) - Optional - Custom HTTP headers for the request. - **cancelToken** (CancelToken?) - Optional - A token to cancel the request. - **onReceiveProgress** (ProgressCallback?) - Optional - A callback function to track download progress. ```