Use the power of native networking libraries with a standard fetch API.
Handle cookies and redirects with ease.
Installation ·
Usage ·
API Reference ·
Contributing
expo-fetcher bridges the gap between the JavaScript fetch API and native networking capabilities ensuring your apps are robust, secure, and performant.
| Feature | Description |
|---|---|
| 🍪 Advanced Cookie Support | Persistent cookie jar on Android. Full visibility of Set-Cookie headers on iOS. |
| ⚡ Native Networking | Uses platform-native networking stacks (NSURLSession/OkHttp) for maximum reliability. |
Fine-grained control over redirect policies: follow, error, or manual. |
|
| ✨ Standard API | Drop-in replacement for fetch. No new concepts to learn. |
| 🔒 Type Safe | Written in TypeScript with complete definitions included. |
Add the package to your Expo or React Native project.
# Using npm
npm install expo-fetcher
# Using yarn
yarn add expo-fetcher
# Using expo
npx expo install expo-fetcherIt works just like the standard fetch you know and love.
import { fetch } from 'expo-fetcher';
// Simple GET request
const response = await fetch('https://api.example.com/data');
const json = await response.json();import { fetch } from 'expo-fetcher';
const uploadData = async () => {
try {
const response = await fetch('https://api.example.com/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer <YOUR_TOKEN>',
},
body: JSON.stringify({ name: 'John Doe', role: 'Developer' }),
});
if (response.ok) {
console.log('Success:', await response.json());
}
} catch (error) {
console.error('Request failed:', error);
}
};Authentication cookies set by the server are automatically stored and managed on Android. On iOS, you have full access to Set-Cookie headers to manage sessions manually if needed.
Note: Android maintains a persistent cookie jar between requests. iOS requests use isolated sessions, so cookies are not automatically carried over to subsequent requests.
import { clearCookies } from 'expo-fetcher';
const handleLogout = async () => {
// Clears the native cookie storage (Android only)
await clearCookies();
console.log('Session cleared');
};Performs a network request.
| Parameter | Type | Required | Description |
|---|---|---|---|
input |
string | URL | Request |
✅ | The URL or Request object. |
init |
RequestInit |
❌ | Optional configuration object. |
| Option | Type | Default | Description |
|---|---|---|---|
method |
'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' |
'GET' |
The HTTP method to use. |
headers |
Headers | Record<string, string> |
{} |
Request headers. |
body |
string | ArrayBuffer | Uint8Array |
undefined |
The body content. |
redirect |
'follow' | 'error' | 'manual' |
'follow' |
Redirect handling policy. |
Clears all cookies stored in the native container.
| Return Type | Description |
|---|---|
Promise<void> |
Resolves when the Android cookie jar has been emptied. |
We welcome contributions! Please see the guidelines below.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.