Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ PODS:
- ReactCommon/turbomodule/core
- ReactNativeDependencies
- Yoga
- NitroModules (0.29.6):
- NitroModules (0.29.8):
- hermes-engine
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -1890,7 +1890,7 @@ DEPENDENCIES:
- FBLazyVector (from `../../node_modules/react-native/Libraries/FBLazyVector`)
- hermes-engine (from `../../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- NitroFetch (from `../../node_modules/react-native-nitro-fetch`)
- NitroModules (from `../../node_modules/react-native-nitro-modules`)
- NitroModules (from `../node_modules/react-native-nitro-modules`)
- RCTDeprecation (from `../../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)
- RCTRequired (from `../../node_modules/react-native/Libraries/Required`)
- RCTSwiftUI (from `../../node_modules/react-native/ReactApple/RCTSwiftUI`)
Expand Down Expand Up @@ -1975,7 +1975,7 @@ EXTERNAL SOURCES:
NitroFetch:
:path: "../../node_modules/react-native-nitro-fetch"
NitroModules:
:path: "../../node_modules/react-native-nitro-modules"
:path: "../node_modules/react-native-nitro-modules"
RCTDeprecation:
:path: "../../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation"
RCTRequired:
Expand Down Expand Up @@ -2127,7 +2127,7 @@ SPEC CHECKSUMS:
FBLazyVector: 4ee5f665093abe339f4b579fc3d59f65c8af196c
hermes-engine: 6e73b6dc6e9f908925b064fcfed5d7ae87f93a6e
NitroFetch: 439b3c58d44e1160c5c2c34e9b02eda08c92014b
NitroModules: f58a7b9fb5b486afd0b0173a605c74c6a83ddf45
NitroModules: 243647de5cfdc3084b20d7b9ac8afc214181242e
RCTDeprecation: b73940ea69ab57c2c59f845b37b09e1d8b0d0588
RCTRequired: f3a52c914af5f19f04d02b2091d83e43cf71676c
RCTSwiftUI: 6dea7b613e8930a973b723c121aa8646374ee694
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react": "19.2.3",
"react-native": "0.85.0-rc.0",
"react-native-nitro-fetch": "workspace:*",
"react-native-nitro-modules": "^0.29.2",
"react-native-nitro-modules": "^0.29.8",
"react-native-safe-area-context": "^5.5.2",
"react-native-worklets-core": "^1.6.2"
},
Expand Down
253 changes: 177 additions & 76 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,82 +346,177 @@ export default function App() {
<View style={styles.container}>
<Text style={styles.title}>Nitro vs Built-in Fetch</Text>
<View style={styles.actions}>
<Button
title={running ? 'Running…' : 'Run Again'}
onPress={run}
disabled={running}
/>
<View style={{ width: 12 }} />
<Button
title="Show Crypto Prices"
onPress={() => {
setShowSheet(true);
loadPrices();
}}
/>
<View style={{ width: 12 }} />
<Button title="POST Request (Worklet)" onPress={sendPostRequest} />
</View>
<View style={[styles.actions, { marginTop: 0 }]}>
<Button
title="Prefetch UUID"
onPress={async () => {
try {
await prefetch(PREFETCH_URL, {
headers: { prefetchKey: PREFETCH_KEY },
});
setPrefetchInfo('Prefetch started');
} catch (e: any) {
setPrefetchInfo(`Prefetch error: ${e?.message ?? String(e)}`);
}
}}
/>
<View style={{ width: 12 }} />
<Button
title="Fetch Prefetched"
onPress={async () => {
try {
const res = await nitroFetch(PREFETCH_URL, {
headers: { prefetchKey: PREFETCH_KEY },
});
console.log('res', res);
const text = await res.text();
const pref = res.headers.get('nitroPrefetched');
setPrefetchInfo(
`Fetched. nitroPrefetched=${pref ?? 'null'} len=${text.length}`
);
} catch (e: any) {
setPrefetchInfo(`Fetch error: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
<View style={[styles.actions, { marginTop: 0 }]}>
<Button
title="Schedule Auto-Prefetch (NativeStorage)"
onPress={async () => {
try {
await prefetchOnAppStart(PREFETCH_URL, {
prefetchKey: PREFETCH_KEY,
});
setPrefetchInfo('Scheduled in NativeStorage');
} catch (e: any) {
setPrefetchInfo(`Schedule error: ${e?.message ?? String(e)}`);
}
}}
/>
<View style={{ width: 12 }} />
<Button
title="Clear Auto-Prefetch"
onPress={async () => {
try {
await removeAllFromAutoprefetch();
setPrefetchInfo('Cleared auto-prefetch queue');
} catch (e: any) {
setPrefetchInfo(`Clear error: ${e?.message ?? String(e)}`);
}
}}
/>
<View style={styles.btnWrap}>
<Button
title={running ? 'Running…' : 'Run Again'}
onPress={run}
disabled={running}
/>
</View>
<View style={styles.btnWrap}>
<Button
title="Crypto Prices"
onPress={() => {
setShowSheet(true);
loadPrices();
}}
/>
</View>
<View style={styles.btnWrap}>
<Button title="POST (Worklet)" onPress={sendPostRequest} />
</View>
<View style={styles.btnWrap}>
<Button
title="FormData (text)"
onPress={async () => {
try {
setPostResult('Sending FormData (text fields)...');
const fd = new FormData();
fd.append('username', 'nitro_user');
fd.append('message', 'Hello from Nitro Fetch FormData!');
fd.append('timestamp', String(Date.now()));

const res = await nitroFetch('https://httpbin.org/post', {
method: 'POST',
body: fd,
});
const json = await res.json();
const form = json.form ?? {};
setPostResult(
`FormData OK! form: ${JSON.stringify(form).substring(0, 150)}`
);
} catch (e: any) {
console.error('FormData error', e);
setPostResult(`FormData error: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
<View style={styles.btnWrap}>
<Button
title="FormData (image)"
onPress={async () => {
try {
setPostResult('Uploading image via FormData...');
const fd = new FormData();
fd.append('caption', 'Test image upload');
fd.append('photo', {
uri: 'https://picsum.photos/id/1/100/100.jpg',
type: 'image/jpeg',
name: 'test_photo.jpg',
} as any);

const res = await nitroFetch('https://httpbin.org/post', {
method: 'POST',
body: fd,
});
const json = await res.json();
const files = Object.keys(json.files ?? {});
const form = Object.keys(json.form ?? {});
setPostResult(
`Image upload OK! files: [${files.join(', ')}], form: [${form.join(', ')}]`
);
} catch (e: any) {
console.error('Image FormData error', e);
setPostResult(`Image FormData: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
<View style={styles.btnWrap}>
<Button
title="FormData (PDF)"
onPress={async () => {
try {
setPostResult('Uploading PDF via FormData...');
const fd = new FormData();
fd.append('title', 'Test PDF document');
fd.append('document', {
uri: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
type: 'application/pdf',
name: 'test_document.pdf',
} as any);

const res = await nitroFetch('https://httpbin.org/post', {
method: 'POST',
body: fd,
});
const json = await res.json();
const files = Object.keys(json.files ?? {});
const form = Object.keys(json.form ?? {});
setPostResult(
`PDF upload OK! files: [${files.join(', ')}], form: [${form.join(', ')}]`
);
} catch (e: any) {
console.error('PDF FormData error', e);
setPostResult(`PDF FormData: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
<View style={styles.btnWrap}>
<Button
title="Prefetch UUID"
onPress={async () => {
try {
await prefetch(PREFETCH_URL, {
headers: { prefetchKey: PREFETCH_KEY },
});
setPrefetchInfo('Prefetch started');
} catch (e: any) {
setPrefetchInfo(`Prefetch error: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
<View style={styles.btnWrap}>
<Button
title="Fetch Prefetched"
onPress={async () => {
try {
const res = await nitroFetch(PREFETCH_URL, {
headers: { prefetchKey: PREFETCH_KEY },
});
console.log('res', res);
const text = await res.text();
const pref = res.headers.get('nitroPrefetched');
setPrefetchInfo(
`Fetched. nitroPrefetched=${pref ?? 'null'} len=${text.length}`
);
} catch (e: any) {
setPrefetchInfo(`Fetch error: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
<View style={styles.btnWrap}>
<Button
title="Schedule Prefetch"
onPress={async () => {
try {
await prefetchOnAppStart(PREFETCH_URL, {
prefetchKey: PREFETCH_KEY,
});
setPrefetchInfo('Scheduled in NativeStorage');
} catch (e: any) {
setPrefetchInfo(`Schedule error: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
<View style={styles.btnWrap}>
<Button
title="Clear Prefetch"
onPress={async () => {
try {
await removeAllFromAutoprefetch();
setPrefetchInfo('Cleared auto-prefetch queue');
} catch (e: any) {
setPrefetchInfo(`Clear error: ${e?.message ?? String(e)}`);
}
}}
/>
</View>
</View>
{!!prefetchInfo && (
<Text style={{ textAlign: 'center', marginBottom: 8 }}>
Expand Down Expand Up @@ -560,7 +655,13 @@ const styles = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
flexWrap: 'wrap',
paddingHorizontal: 8,
marginBottom: 8,
gap: 6,
},
btnWrap: {
marginVertical: 2,
},
backdrop: {
flex: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ object AutoPrefetcher {
headers = headerObjs,
bodyString = null,
bodyBytes = null,
bodyFormData = null,
timeoutMs = null,
followRedirects = null
)
Expand Down
Loading
Loading