搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.1

fetch_client

基於 Fetch API 的 http 套件客戶端,可在 Web 上啟用串流和可取消的請求,功能更強大。

Web
近 30 天下載
10.1萬
喜歡數
44
Pub 分數
140

安裝套件

flutter pub add fetch_client

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Fetch_client 是一個 Flutter 套件,提供類似 Fetch API 的介面來發起 HTTP 請求,專為 Web 平台設計。它支援串流回應和可取消的請求,從而提升 Web 應用的效能與使用者體驗。基於 http 套件建構,它提供現代化且直覺的語法,同時保持與 Dart 異步程式設計模型的相容性。非常適合希望在以 Web 為導向的 Flutter 應用中,以熟悉且高效的方式處理 HTTP 互動的開發者。

適用情境

  • 在基於Web的Flutter應用中發起HTTP請求
  • 處理來自 API 的串流回應
  • 在導航期間取消進行中的請求
  • 實現即時資料取得
  • 使用異步操作構建響應式 Web 界面

主要特色

  • Fetch API 類似語法
  • 對串流式回應的支援
  • 可取消的請求
  • 以網頁為先的設計
  • http 包的輕量級封裝

適合對象

  • 專注於網路的Flutter開發者
  • 需要即時資料的應用程式
  • 偏好現代 HTTP 模式的開發人員
  • 需要請求取消的項目
  • 使用流式數據流的團隊

使用建議

  • 有限的功能,僅限於網頁平台
  • 依賴 http 包進行核心操作
  • 移動平台無原生支援
  • 不適用於超出網頁的複雜HTTP情境
  • 在Web上下文中需要仔細處理流

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Fetch Client

pub package package publisher

This package provides package:http client based on Fetch API with WASM support.

It's a drop-in solution for extensions with Manifest V3.

Features

  • WASM-ready internals.
  • Cancel requests.
  • Support data streaming:
    • Get response as Stream.
    • Optionally, send Stream as request body (supported only in Chromium 105+ based browsers).
  • Get access to redirect URL and status.
  • Support non-200 responses (fetch will only fail on network errors).
  • Simulate redirects responses via probe request and artificial location header.

Notes

Large payload

This module maps keepalive to BaseRequest.persistentConnection which is true by default.

Fetch spec says that maximum request size with keepalive flag is 64KiB:

4.5. HTTP-network-or-cache fetch

8.10.5: If the sum of contentLength and inflightKeepaliveBytes is greater than 64 kibibytes, then return a network error.

Source: Fetch. Living Standard — Last Updated 19 June 2023

Therefore if your request is larger than 64KiB (this includes some other data, such as headers) BaseRequest.persistentConnection will be ignored and treated as false.

Request streaming

Request streaming is supported only in Chromium 105+ based browsers and requires the server to use HTTP/2 or HTTP/3.

See MDN compatibility chart and Chrome Developers' blog for more info.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案