<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by IB Akhrorov on Medium]]></title>
        <description><![CDATA[Stories by IB Akhrorov on Medium]]></description>
        <link>https://medium.com/@islam_akhrarov?source=rss-cafad7a41ee3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XaoASWZbeOSbsNRWH4C66Q.jpeg</url>
            <title>Stories by IB Akhrorov on Medium</title>
            <link>https://medium.com/@islam_akhrarov?source=rss-cafad7a41ee3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 07:52:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@islam_akhrarov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Limitations of the Dart HTTP Library and a Solution for Web Streaming]]></title>
            <link>https://medium.com/@islam_akhrarov/title-the-limitations-of-the-dart-http-library-and-a-solution-for-web-streaming-574818b360d9?source=rss-cafad7a41ee3------2</link>
            <guid isPermaLink="false">https://medium.com/p/574818b360d9</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[flutter-web]]></category>
            <category><![CDATA[streamedrequest]]></category>
            <category><![CDATA[browserclient]]></category>
            <dc:creator><![CDATA[IB Akhrorov]]></dc:creator>
            <pubDate>Fri, 09 Jun 2023 08:50:31 GMT</pubDate>
            <atom:updated>2023-06-09T09:01:46.361Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction:<br>The Dart programming language offers a comprehensive HTTP library that allows developers to make HTTP requests and handle responses efficiently. However, one limitation of this library is the lack of support for `StreamedRequest` in web applications. In this article, we will explore the reasons behind this limitation and introduce a solution to overcome it using the `fetch_client` library.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oLBopRa1X__2L8KNuKXbrA.png" /><figcaption>Source of the image: <a href="https://blog.arrowhitech.com/flutter-for-web/">https://blog.arrowhitech.com/flutter-for-web/</a></figcaption></figure><h4>Understanding the Limitations:</h4><p>The `BrowserClient` class, which is a part of the `dart:html` package, serves as the HTTP client for web-based applications in Dart. It utilizes XMLHttpRequests (XHR) to send and receive HTTP requests and responses. However, this client inherits some of the restrictions imposed by XMLHttpRequest, which prevent it from fully supporting the `StreamedRequest` functionality.</p><p>Specifically, the `BrowserClient` disregards several fields from the `BaseRequest` class, including `contentLength`, `persistentConnection`, `followRedirects`, and `maxRedirects`. Additionally, it lacks the capability to stream requests or responses. Instead, the client only sends a request or receives a response once all the data is available, hindering the ability to process large amounts of data efficiently.</p><h4>Introducing the Solution:</h4><p>To overcome the limitations posed by the Dart HTTP library in web applications, developers can utilize the `fetch_client` library. This library leverages the Fetch API, a modern web standard, to perform HTTP requests and handle responses in the browser.</p><p>The Fetch API provides a more powerful and flexible approach to making HTTP requests. It supports streaming requests and responses, allowing data to be transmitted in chunks rather than waiting for the entire payload to be available. By utilizing the `fetch_client` library, developers can ensure that the `StreamedRequest` functionality works as expected in web applications.</p><h4>Implementing the Solution:</h4><p>To incorporate the `fetch_client` library into your project effectively, you need to import it conditionally based on the platform. This ensures that the appropriate HTTP client is used for each platform while maintaining compatibility with non-web platforms.</p><p>Let’s take a look at an example implementation:</p><pre><br>// client.dart<br>import ‘package:http/http.dart’;<br><br>Client createClient(){<br> return Client();<br>}</pre><pre><br>// client_web.dart<br>import ‘package:fetch_client/fetch_client.dart’;<br>import ‘package:http/http.dart’;<br><br>Client createClient() {<br> return FetchClient(mode: RequestMode.cors);<br>}</pre><pre><br>// di.dart<br>import ‘client.dart’ if (dart.library.html) ‘client_web.dart’;<br>import ‘package:get_it/get_it.dart’;<br>import ‘package:http/http.dart’;<br><br>final injector = GetIt.instance;<br><br>void setupDependencies() {<br> injector.registerFactory&lt;Client&gt;(() {<br> return createClient();<br> });<br>}</pre><p>In the above example, we define two separate client implementations: `client.dart` for non-web platforms and `client_web.dart` for web applications. The `createClient()` function returns the appropriate client instance based on the platform.</p><p>In the dependency injection (DI) file, `di.dart`, we import the appropriate client implementation conditionally. If the current platform is a web platform, the `client_web.dart` file is imported; otherwise, the `client.dart` file is used. The `injector` registers the `Client` factory with the appropriate implementation, ensuring that the correct HTTP client is instantiated based on the platform.</p><h3>Conclusion:</h3><p>While the Dart HTTP library provides extensive support for making HTTP requests and handling responses, it has some limitations when it comes to streaming requests in web applications. By utilizing the `fetch_client` library, which leverages the Fetch API, developers can overcome these limitations and enable streaming functionality in their</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=574818b360d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>