@exodus/networking-mobile

中文文档
3.0.1发布于 2026/10/14MITTypeScriptES Module近 30 天下载 1.1万

Implementation of networking-spec for a React Native context

原始使用文档
文档目录4 节
  1. Installing
  2. Usage
  3. @exodus/networking-mobile/http + form
  4. @exodus/networking-mobile/cookie

@exodus/networking-mobile

This repository contains the implementation of the networking-spec for React Native contexts.

Installing

pnpm add @exodus/networking-mobile

Usage

The following sections will outline how to use the various modules that are part of this package.

@exodus/networking-mobile/http + form

The React Native fetch implementation does not support a spec compliant FormData object. In order to have an API that is similar to what we are used to from the Browser, this module ships with its own FormData implementation.

To use it, import it and add data as you're used to:

import { FormData } from '@exodus/networking-mobile/form'

const formData = new FormData()
formData.append('name', 'Bruce Wayne')

// set is also available
formData.set('name', 'Batman')

// ...and many more: delete, get, getAll, entries, keys, values

As opposed to the Browser implementation, the RN FormData is not just a data container, but also knows how to serialize itself. Therefore the FormData implementation shipping with this module (which follows the Browser spec), cannot directly be used with RN's fetch.

To overcome this limitation, use the HttpClient that is part of this module. It comes with a fetch function that has the same signature as RN's fetch but can handle our FormData.

import { FormData, File } from '@exodus/networking-mobile/form'
import { createHttpClient } from '@exodus/networking-mobile/http'
import RNFS from '@exodus/react-native-fs'

const client = new createHttpClient({
  fs: RNFS,
  os: 'android',
  createUuid: uuidv4,
  hashString: shasum,
  logger,
})

const formData = new FormData()
formData.set('passport', new File(buffer, 'passport.jpg'))

await client.fetch('https://wayne.enterprises/upload', { method: 'POST', body: formData })

The client transforms FormData by writing files to the temporary folder, and appending the file URI, MIME type, and file name to an RN FormData object that is then passed to RN's fetch. Any temporarily created files are removed when the requests completes - successfully or otherwise.

Please note that the file used above is also provided by this module. It receives an object of type Buffer, a name, and optional properties to set the MIME type and last modified date. The MIME type takes no effect if used in conjunction with the HttpClient, since the client automatically derives the MIME type from the file extension.

@exodus/networking-mobile/cookie

The mobile CookieJar has to be instantiated with the platform it is running on.

import { CookieJar } from '@exodus/networking-browser/cookie'

const jar = new CookieJar('android')

A cookie can be removed by specifying its host and name (and optionally its path)

await jar.remove({ name: 'csrf', host: 'sub.domain.com' })

To get rid of all cookies, use the following:

await jar.removeAll()

版本与发布记录

@exodus/networking-mobile 共发布 22 个版本,首次发布于 2022/05/11;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.0.1latest2026/10/141 个月前
3.0.02025/05/131.5 年前
2.0.22025/01/081.8 年前
2.0.12024/11/022 年前
2.0.02024/10/222 年前
1.1.132022/11/153 年前

关于 @exodus/networking-mobile 的常见问题

@exodus/networking-mobile 是什么?

Implementation of networking-spec for a React Native context

如何安装 @exodus/networking-mobile?

在项目目录运行 npm install @exodus/networking-mobile,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react-native(>=0.64.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@exodus/networking-mobile 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@exodus/networking-mobile 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@exodus/networking-mobile 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@exodus/networking-mobile 可以商用吗?

@exodus/networking-mobile 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/networking-mobile 的下载量有多少?

根据 npm 官方下载统计,@exodus/networking-mobile 在 2026/10/14 – 2026/11/12 这 30 天内被下载 10,634 次,日均约 354 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/networking-mobile 还在维护吗?

最新版本 3.0.1 发布于 2026/10/14(1 个月前);至今共发布 22 个版本,其中过去 12 个月发布了 1 个;首次发布于 2022/05/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。