### Start the Example App Packager Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/CONTRIBUTING.md Start the Metro bundler for the example application. ```shell bun example start ``` -------------------------------- ### Android Setup for Prefetching Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/nitro-fetch/references/prefetching.md Add this line to your `MainApplication.kt` to enable `prefetchOnAppStart` on Android. The `try-catch` block prevents crashes on fresh installs. ```kotlin import com.margelo.nitro.nitrofetch.AutoPrefetcher class MainApplication : Application(), ReactApplication { override fun onCreate() { super.onCreate() try { AutoPrefetcher.prefetchOnStart(this) } catch (_: Throwable) {} loadReactNative(this) } } ``` -------------------------------- ### Basic Prefetch and Fetch Example Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/prefetch.md Demonstrates how to start a prefetch request and then consume its result later using the fetch function. Ensure the prefetchKey is provided in headers. ```typescript import { fetch, prefetch } from 'react-native-nitro-fetch'; // 1) Start prefetch await prefetch('https://httpbin.org/uuid', { headers: { prefetchKey: 'uuid' } }); // 2) Consume later const res = await fetch('https://httpbin.org/uuid', { headers: { prefetchKey: 'uuid' } }); console.log('prefetched?', res.headers.get('nitroPrefetched')); ``` -------------------------------- ### Install Optional Dependencies Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/nitro-fetch/SKILL.md Install optional dependencies for WebSockets and TextDecoder support. After installation, rebuild the application. ```bash npm install react-native-nitro-websockets react-native-nitro-text-decoder ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/CONTRIBUTING.md Build and run the example application on an iOS simulator or device. ```shell bun example ios ``` -------------------------------- ### Setup react-native-nitro-text-decoder Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/nitro-fetch/references/text-decoder.md Install the package and its peer dependency react-native-nitro-modules. For iOS, run pod install. ```bash # pick your manager npm install react-native-nitro-text-decoder react-native-nitro-modules yarn add react-native-nitro-text-decoder react-native-nitro-modules bun add react-native-nitro-text-decoder react-native-nitro-modules cd ios && pod install ``` -------------------------------- ### Run Example App on Android Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/CONTRIBUTING.md Build and run the example application on an Android device or emulator. ```shell bun example android ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/CONTRIBUTING.md Install all necessary dependencies for the monorepo using Bun workspaces. ```shell bun install ``` -------------------------------- ### Install Pods and Rebuild for iOS WebSockets Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/getting-started.md After installing WebSocket packages, install native pods and rebuild the iOS app. ```bash cd ios && pod install && cd .. npx react-native run-ios ``` -------------------------------- ### Start Local Development Server Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/README.md Starts a local development server for live previewing changes. Changes are reflected live without server restarts. ```bash yarn start ``` -------------------------------- ### Install Bun Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/CONTRIBUTING.md Install Bun, the JavaScript runtime and package manager used for this project. ```shell curl -fsSL https://bun.sh/install | bash ``` -------------------------------- ### Install Dependencies Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/README.md Installs project dependencies using Yarn. ```bash yarn ``` -------------------------------- ### Basic WebSocket Usage Example Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/websockets.md A complete example demonstrating how to connect to a WebSocket echo server, send a message, and handle connection events including closure. ```typescript const ws = new NitroWebSocket('wss://echo.websocket.org'); ws.onopen = () => console.log('open'); ws.onmessage = (e) => console.log('message', e.data, e.isBinary); ws.onerror = (err) => console.error(err); ws.onclose = (e) => console.log('closed', e.code, e.reason); ws.send('hello'); ws.close(1000, 'bye'); ``` -------------------------------- ### Install Dependencies Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/getting-started.md Install the react-native-nitro-fetch and react-native-nitro-modules packages using npm. ```bash npm install react-native-nitro-fetch react-native-nitro-modules ``` -------------------------------- ### Install react-native-worklets Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/worklets.md Install the react-native-worklets package using npm. ```bash npm install react-native-worklets ``` -------------------------------- ### Install Dependencies for NitroWebSocket Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/nitro-fetch/references/migrate-from-rn-ws.md Install the necessary packages for NitroWebSocket, NitroFetch, and NitroTextDecoder. Ensure to run `pod install` for iOS after installation. ```bash npm install \ react-native-nitro-websockets \ react-native-nitro-fetch \ react-native-nitro-text-decoder \ react-native-nitro-modules cd ios && pod install ``` -------------------------------- ### Install native pods and rebuild Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/websockets.md After installing npm packages, navigate to the ios directory to install pods and then rebuild the React Native application. ```sh cd ios && pod install && cd .. npx react-native run-ios # or run-android ``` -------------------------------- ### prefetchOnAppStart(input, { prefetchKey }) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/api.md Enqueues a request to be prefetched automatically on the next app start by storing it in native storage. ```APIDOC ## prefetchOnAppStart(input, { prefetchKey }) ### Description Enqueues a request to be prefetched at the next app start by writing into native storage. Enqueued requests are stored in native storage and automatically executed on the next app start on both platforms. ### Method `prefetchOnAppStart` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts await prefetchOnAppStart(url, { prefetchKey: 'my-key' }); ``` ### Response #### Success Response (200) Indicates the request has been successfully enqueued for prefetching. ``` -------------------------------- ### Android HTTP Fetch Trace Events Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md These examples show how to use `android.os.Trace.beginAsyncSection` and `endAsyncSection` to mark the start and end of HTTP fetch requests for tracing. ```java Trace.beginAsyncSection("NitroFetch GET /path", cookie) ``` ```java Trace.endAsyncSection("NitroFetch GET /path", cookie) ``` -------------------------------- ### Install Nitro Fetch Skill for Gemini CLI Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/README.md Install the nitro-fetch skill for the Gemini CLI. Use the --scope workspace flag to install it only for the current repository. ```bash gemini skills install https://github.com/margelo/react-native-nitro-fetch.git ``` -------------------------------- ### prefetch(input, init) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/api.md Starts a background request natively when possible. Requires a `prefetchKey` and can be consumed later using `fetch` with the same key. A successful consumption includes the `nitroPrefetched: true` header. ```APIDOC ## prefetch(input, init) ### Description Starts a background request in native when possible. Requires a `prefetchKey` provided either via `headers: { prefetchKey }` or `init.prefetchKey`. Later, call `fetch(url, { headers: { prefetchKey } })` to consume a fresh or pending prefetched result. On success, the response will include header `nitroPrefetched: true`. ### Method `prefetch` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts // To initiate prefetch await prefetch(url, { headers: { prefetchKey: 'my-key' } }); // To consume prefetched data const res = await fetch(url, { headers: { prefetchKey: 'my-key' } }); ``` ### Response #### Success Response (200) Response from the prefetched request. Includes `nitroPrefetched: true` header if consumed successfully. ``` -------------------------------- ### Run Nitrogen for Boilerplate Generation Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/CONTRIBUTING.md Generate required boilerplate code using Nitrogen, essential for the example app to build. Run this after changes to *.nitro.ts files or for the initial setup. ```shell bun nitrogen ``` -------------------------------- ### Install Nitro Fetch Skill for OpenCode Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/README.md Clone the nitro-fetch repository and copy the skill to the .opencode/skill directory. This allows OpenCode to access the skill. ```bash git clone https://github.com/margelo/react-native-nitro-fetch.git /tmp/nitro-fetch \ && cp -r /tmp/nitro-fetch/skills/nitro-fetch .opencode/skill/ ``` -------------------------------- ### Install Nitro WebSockets and Text Decoder Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/getting-started.md Install the optional WebSocket package and its peer dependency for text decoding. ```bash npm i react-native-nitro-websockets react-native-nitro-text-decoder ``` -------------------------------- ### Enable NetworkInspector at App Startup Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/nitro-fetch/references/network-inspector.md Example of how to enable the NetworkInspector with custom options during application startup, typically gated by __DEV__. ```typescript // src/setupInspector.ts import { NetworkInspector } from 'react-native-nitro-fetch'; if (__DEV__) { NetworkInspector.enable({ maxEntries: 500, maxBodyCapture: 4096, }); } ``` ```javascript // index.js import './src/setupInspector'; // ... ``` -------------------------------- ### Install Pods for iOS Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/example/README.md Installs the native dependencies for the iOS project using CocoaPods. This should be run after bundle install or when native dependencies are updated. ```sh bundle exec pod install ``` -------------------------------- ### prefetchOnAppStart(input, { prefetchKey }) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/api.md Enqueues a request to be prefetched when the application starts next. This is specific to Android and uses Shared Preferences to manage the queue. ```APIDOC ## `prefetchOnAppStart(input, { prefetchKey })` (Android) ### Description Enqueues a request to be prefetched at the next app start by writing into Shared Preferences under `nitrofetch_autoprefetch_queue`. ### Method `prefetchOnAppStart` ### Parameters - **input**: RequestInfo (URL or Request object) - **options**: Object - **prefetchKey**: `string` - A key to identify the prefetched request. ### Platform Android ``` -------------------------------- ### Install react-native-nitro-text-decoder Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/streaming.md Install the text decoder package required for streaming UTF-8 data. ```bash npm i react-native-nitro-text-decoder ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/example/README.md Starts the Metro, the JavaScript bundler for React Native. This command is essential before building or running the app. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install nitro-fetch Skill for Gemini CLI Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/skills.md Install the react-native-nitro-fetch skill for the Gemini CLI using its command-line interface. ```bash gemini skills install https://github.com/margelo/react-native-nitro-fetch.git ``` -------------------------------- ### Cronet Engine Initialization (C++) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/cronet-android.md This C++ code demonstrates how to initialize the Cronet engine with custom parameters and ensure it's started successfully. It includes header declarations and the implementation for initialization and shutdown. ```cpp // cronet_bridge.hpp #include bool cronet_init(); void cronet_shutdown(); bool cronet_request(const NitroRequest&, NitroResponse* out); // cronet_bridge.cpp static Cronet_EnginePtr g_engine = nullptr; bool cronet_init() { if (g_engine) return true; Cronet_EngineParamsPtr params = Cronet_EngineParams_Create(); Cronet_EngineParams_enable_quic_set(params, true); Cronet_EngineParams_user_agent_set(params, Cronet_String_Create("NitroFetch/0.1")); g_engine = Cronet_Engine_Create(); auto rc = Cronet_Engine_StartWithParams(g_engine, params); Cronet_EngineParams_Destroy(params); return rc == CRONET_RESULT_SUCCESS; } ``` -------------------------------- ### Install react-native-nitro-fetch Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/README.md Install the core library and its dependency for Nitro Modules. Ensure your React Native version is compatible. ```sh npm i react-native-nitro-fetch react-native-nitro-modules ``` -------------------------------- ### Vendoring Cronet Framework in Podspec Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/cronet-ios.md Example of how to specify the Cronet framework in a Podspec file for vendoring. ```ruby s.vendored_frameworks = 'path/to/Cronet.framework' ``` -------------------------------- ### Trigger Native Prefetch on App Start in AppDelegate Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/ios.md Integrate this method into your AppDelegate.swift file to enable automatic prefetching of resources when the application launches. This ensures that essential data is available as soon as the app starts. ```swift import NitroFetch @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { NitroAutoPrefetcher.prefetchOnStart() return true } } ``` -------------------------------- ### Rebuild App for Native Client Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/troubleshooting.md Rebuild your application after installing dependencies to ensure the native client is available and avoid silent fallback to JS fetch. ```bash npx react-native run-android npx react-native run-ios ``` -------------------------------- ### Install react-native-nitro-websockets and dependencies Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/websockets.md Install the WebSocket module, Nitro Modules, and the text-decoder peer dependency using npm. ```sh npm i react-native-nitro-websockets react-native-nitro-text-decoder react-native-nitro-modules ``` -------------------------------- ### Enable Both Tracing Types on iOS Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md Set both environment variables before running `pod install` to enable native tracing for both HTTP fetch and WebSocket operations on iOS. ```bash # Both at once NITROFETCH_TRACING=1 NITRO_WS_TRACING=1 bundle exec pod install ``` -------------------------------- ### Record and Pull Trace (Android) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md These bash commands push the trace configuration to the device, start the Perfetto trace recording, and then pull the resulting trace file back to your local machine. ```bash # Push config and start trace adb push trace_config.pbtx /data/local/tmp/ ``` ```bash adb shell perfetto --config /data/local/tmp/trace_config.pbtx --out /data/local/tmp/trace.perfetto-trace ``` ```bash # After using your app, pull the trace adb pull /data/local/tmp/trace.perfetto-trace . ``` -------------------------------- ### Android Setup for WebSocket Pre-warming Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/nitro-fetch/references/websocket-prewarm.md Integrate WebSocket pre-warming into your Android application by adding a single line to your Application.onCreate() method. This ensures the native service can bootstrap WebSocket connections on app startup. ```kotlin import com.margelo.nitro.nitrofetchwebsockets.NitroWebSocketAutoPrewarmer class MainApplication : Application(), ReactApplication { override fun onCreate() { super.onCreate() NitroWebSocketAutoPrewarmer.prewarmOnStart(this) loadReactNative(this) } } ``` -------------------------------- ### Basic Fetch Usage Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/README.md Import and use the fetch function as a direct replacement for the standard fetch API. This example demonstrates fetching JSON data. ```ts import { fetch } from 'react-native-nitro-fetch' const res = await fetch('https://httpbin.org/get') const json = await res.json() ``` -------------------------------- ### Install Native Dependencies and Clear Cache Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/worklets.md Install native dependencies for iOS using CocoaPods and clear the Metro bundler cache to ensure changes are applied. ```bash # iOS cd ios && pod install && cd .. # Clear Metro cache npm start -- --reset-cache ``` -------------------------------- ### Enable HTTP Fetch Tracing on iOS Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md Set this environment variable before running `pod install` to enable native tracing for HTTP fetch operations. This injects compile-time flags for `os_signpost` intervals. ```bash # HTTP fetch tracing (os_signpost intervals in Swift) NITROFETCH_TRACING=1 bundle exec pod install ``` -------------------------------- ### Prefetching for Next App Launch Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/README.md Schedule data to be prefetched when the application starts next time. This improves initial load performance. ```ts import { prefetchOnAppStart } from 'react-native-nitro-fetch' await prefetchOnAppStart('https://httpbin.org/uuid', { prefetchKey: 'uuid' }) ``` -------------------------------- ### Enable and Configure Network Inspector Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md Start recording network activity with optional configuration for buffer size and body capture limits. Ensure this is called before network requests you wish to inspect. ```typescript import { NetworkInspector } from 'react-native-nitro-fetch'; // Start recording NetworkInspector.enable(); // Optionally configure limits NetworkInspector.enable({ maxEntries: 500, // ring-buffer size (default 500) maxBodyCapture: 4096, // max bytes captured per body (default 4096) }); // Stop recording NetworkInspector.disable(); ``` -------------------------------- ### File Upload Example Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/form-data.md Use this snippet to upload files along with other form fields. Ensure the file object includes 'uri', 'type', and 'name'. ```typescript import { fetch } from 'react-native-nitro-fetch'; const fd = new FormData(); fd.append('username', 'nitro_user'); fd.append('avatar', { uri: 'file:///path/to/photo.jpg', type: 'image/jpeg', name: 'avatar.jpg', }); const res = await fetch('https://httpbin.org/post', { method: 'POST', body: fd, }); const json = await res.json(); ``` -------------------------------- ### Manual Android Setup for Auto-Prefetch Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/prefetch.md Manually enable auto-prefetch on Android by calling AutoPrefetcher.prefetchOnStart() in your MainApplication.kt. Place this call as early as possible in onCreate() to maximize network time savings. ```kotlin import com.margelo.nitro.nitrofetch.AutoPrefetcher class MainApplication : Application(), ReactApplication { // ... override fun onCreate() { super.onCreate() // Start any queued auto-prefetch requests as early as possible try { AutoPrefetcher.prefetchOnStart(this) } catch (_: Throwable) {} loadReactNative(this) } } ``` -------------------------------- ### Enable WebSocket Tracing on iOS Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md Set this environment variable before running `pod install` to enable native tracing for WebSocket operations. This injects compile-time flags for `os_signpost` events/intervals. ```bash # WebSocket tracing (os_signpost events/intervals in C++) NITRO_WS_TRACING=1 bundle exec pod install ``` -------------------------------- ### Install nitro-fetch Skill for Codex / ChatGPT Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/skills.md Add the react-native-nitro-fetch skill for Codex or ChatGPT using npx. ```bash npx codex-plugin add margelo/react-native-nitro-fetch ``` -------------------------------- ### Basic NitroWebSocket usage example Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/websockets.md Connect to a WebSocket server, handle open, message, error, and close events, send data, and close the connection. ```typescript const ws = new NitroWebSocket('wss://echo.websocket.org') ws.onopen = () => console.log('open') ws.onmessage = (e) => console.log('message', e.data, e.isBinary) ws.onerror = (err) => console.error(err) ws.onclose = (e) => console.log('closed', e.code, e.reason) ws.send('hello') ws.close(1000, 'bye') ``` -------------------------------- ### iOS HTTP Fetch Trace Events (os_signpost) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md These examples show how to use `os_signpost` to mark the beginning and end of HTTP fetch requests, including method, path, and status information. ```swift os_signpost(.begin, "NitroFetch", "GET /path") ``` ```swift os_signpost(.end, "NitroFetch", "status=200 bytes=N") ``` -------------------------------- ### Start a Prefetch Request Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/android.md Initiates a prefetch for a given URL. This is useful for fetching data in the background that might be needed soon. Ensure the 'react-native-nitro-fetch' library is imported. ```typescript import { prefetch } from 'react-native-nitro-fetch'; await prefetch('https://httpbin.org/uuid', { headers: { prefetchKey: 'uuid' } }); ``` -------------------------------- ### iOS WebSocket Trace Events (os_signpost) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/inspection.md These examples demonstrate using `os_signpost` for tracing WebSocket lifecycle events, including connection, send, receive, close, and error states. ```swift interval begin: "NitroWS" with URL ``` ```swift interval end: "NitroWS" "connected" ``` ```swift event: "send text bytes" ``` ```swift event: "send binary bytes" ``` ```swift event: "receive text" ``` ```swift event: "receive binary" ``` ```swift event: "close code= clean=<0|1>" ``` ```swift event: "error " ``` -------------------------------- ### Cross-Launch Prefetching for Cold Starts Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/skills/nitro-fetch/references/prefetching.md Use `prefetchOnAppStart` to cache data before the React Native app loads. This ensures data is available in the cache by the time the relevant screen mounts, improving cold-start performance. ```typescript await prefetchOnAppStart('https://api.example.com/feed', { prefetchKey: 'home-feed', headers: { Authorization: `Bearer ${token}` }, }); ``` -------------------------------- ### Install CocoaPods Dependencies Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/example/README.md Installs Ruby dependencies for CocoaPods, which is necessary for building iOS applications. Run this before installing pod dependencies. ```sh bundle install ``` -------------------------------- ### Setting Up Local Include Directories Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/packages/react-native-nitro-text-decoder/android/CMakeLists.txt Specifies directories from which header files can be included during compilation, making source files accessible. ```cmake include_directories( "src/main/cpp" "../cpp" ) ``` -------------------------------- ### prefetch(input, init) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/api.md Initiates a background network request when possible, requiring a `prefetchKey` to be provided. This allows for later consumption of the prefetched result using the same `prefetchKey`. ```APIDOC ## `prefetch(input, init)` ### Description Starts a background request in native when possible. Requires a `prefetchKey` provided either via `headers: { prefetchKey }` or `init.prefetchKey`. Later, call `fetch(url, { headers: { prefetchKey } })` to consume a fresh or pending prefetched result. On success, response will include header `nitroPrefetched: true`. ### Method `prefetch` ### Parameters - **input**: RequestInfo (URL or Request object) - **init**: RequestInit (Optional configuration object for the request) - **prefetchKey**: `string` - A key to identify the prefetched request. - **headers**: `Headers` | Array<[string, string]> | Record - Headers for the request, can include `prefetchKey`. ### Response - Response will include header `nitroPrefetched: true` on success. ``` -------------------------------- ### Build Static Website Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/README.md Generates static website content into the 'build' directory for hosting. ```bash yarn build ``` -------------------------------- ### Prefetch with prefetchKey in init Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/prefetch.md Shows an alternative way to provide the prefetchKey directly in the init options for the prefetch function. ```typescript await prefetch('https://httpbin.org/uuid', { prefetchKey: 'uuid' } as any); ``` -------------------------------- ### Install nitro-fetch Skill for Claude Code Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/skills.md Use these commands to add the react-native-nitro-fetch plugin and install the nitro-fetch skill for Claude Code. ```bash /plugin marketplace add margelo/react-native-nitro-fetch /plugin install nitro-fetch@react-native-nitro-fetch ``` -------------------------------- ### fetch(input, init) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/api.md A drop-in replacement for the global `fetch` API. It supports various header formats and body types, returning a `Response` object or a minimal object with methods to access the response body. ```APIDOC ## fetch(input, init) ### Description Drop-in replacement for the global `fetch`. Accepts `Headers`, array pairs, or plain object for `init.headers`. Body supports: `string`, `URLSearchParams`, `ArrayBuffer`, and typed arrays. Returns a `Response` when available; otherwise a minimal object with `arrayBuffer()`, `text()`, `json()`, and `headers`. ### Method `fetch` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ts import { fetch } from 'react-native-nitro-fetch'; const res = await fetch('https://jsonplaceholder.typicode.com/todos/1'); const data = await res.json(); ``` ### Response #### Success Response (200) `Response` object or a minimal object with `arrayBuffer()`, `text()`, `json()`, and `headers`. ``` -------------------------------- ### Enqueue Request for App Start Prefetch Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/prefetch.md Enqueue requests to be fetched automatically on the next app start. This functionality is supported on both Android and iOS. ```typescript import { prefetchOnAppStart } from 'react-native-nitro-fetch'; await prefetchOnAppStart('https://httpbin.org/uuid', { prefetchKey: 'uuid', }); ``` -------------------------------- ### Set Up Local Include Directories Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/packages/react-native-nitro-fetch/android/CMakeLists.txt Configures the include paths for local C++ source files. This allows the compiler to find headers within the 'src/main/cpp' and '../cpp' directories. ```cmake # Set up local includes include_directories("src/main/cpp" "../cpp") ``` -------------------------------- ### Deploy Website using SSH Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/README.md Deploys the website using SSH, suitable for GitHub pages hosting. ```bash USE_SSH=true yarn deploy ``` -------------------------------- ### Rebuild React Native App Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/getting-started.md Rebuild your application to link the newly installed Nitro module. ```bash npx react-native run-android # or npx react-native run-ios ``` -------------------------------- ### fetch(input, init) Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/api.md A drop-in replacement for the global fetch function. It enhances the standard fetch by accepting various formats for headers and supporting multiple body types. It returns a Response object or a minimal object with methods to access the response body. ```APIDOC ## `fetch(input, init)` ### Description Drop-in replacement for the global `fetch`. Accepts `Headers`, array pairs, or plain object for `init.headers`. Body supports: `string`, `URLSearchParams`, `ArrayBuffer`, and typed arrays. Returns a `Response` when available; otherwise a minimal object with `arrayBuffer()`, `text()`, `json()`, and `headers`. ### Method `fetch` ### Parameters - **input**: RequestInfo (URL or Request object) - **init**: RequestInit (Optional configuration object for the request) - **headers**: `Headers` | Array<[string, string]> | Record - Headers for the request. - **body**: `string` | `URLSearchParams` | `ArrayBuffer` | TypedArray - The body of the request. ### Request Example ```ts import { fetch } from 'react-native-nitro-fetch'; const res = await fetch('https://jsonplaceholder.typicode.com/todos/1'); const data = await res.json(); ``` ### Response - **Response** or minimal object with `arrayBuffer()`, `text()`, `json()`, and `headers`. ``` -------------------------------- ### Invoke nitro-fetch Skill for Claude Code Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/skills.md After installation, you can explicitly invoke the nitro-fetch skill in Claude Code using this command. ```bash /nitro-fetch ``` -------------------------------- ### Run Parsing on Worklet Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs/worklets.md Use `nitroFetchOnWorklet` to execute a mapping function off the JS thread. Ensure `react-native-worklets` is installed for this functionality. ```typescript import { nitroFetchOnWorklet } from 'react-native-nitro-fetch'; const map = (payload: { bodyString?: string }) => { 'worklet'; return JSON.parse(payload.bodyString ?? '{}'); }; const data = await nitroFetchOnWorklet('https://httpbin.org/get', undefined, map, { preferBytes: false }); ``` -------------------------------- ### Prefetch on Navigation Intent with useQuery Source: https://github.com/margelo/react-native-nitro-fetch/blob/main/docs-website/docs/prefetch.md Initiate a prefetch request when a user intends to navigate to a new screen. This pattern, often used with TanStack Query, ensures that data is ready or in flight by the time the destination screen mounts, leading to a smoother user experience. ```typescript // List screen import { prefetch, fetch as nitroFetch } from 'react-native-nitro-fetch'; import { useNavigation } from '@react-navigation/native'; const PREFETCH_KEY = 'user:42'; const URL = 'https://api.example.com/users/42'; function Row() { const nav = useNavigation(); return (