- Base mode: install only
react-native-nitro-api(JS cache fallback). - Nitro mode: additionally install
react-native-nitro-modulesin the app and run iOS pods.
npm install react-native-nitro-api
npm install react-native-nitro-modules
cd ios && pod installCreates an API client instance.
createAPI({
baseURL: string,
timeout?: number,
headers?: Record<string, string>,
cache?: {
enabled?: boolean,
defaultTTL?: number,
staleWhileRevalidate?: boolean,
},
auth?: {
storage?: TokenStorage,
getAccessToken?: () => Promise<string | null> | string | null,
refreshToken?: (context) => Promise<{ accessToken: string; refreshToken?: string | null }>,
shouldRefresh?: (status: number) => boolean,
},
debug?: boolean,
dedupe?: boolean,
offlineQueue?: boolean,
})All methods return typed response data.
Multipart upload helper.
await api.upload('/media/upload', {
files: { uri: 'file:///tmp/photo.jpg', name: 'photo.jpg', type: 'image/jpeg' },
fields: { folder: 'avatars' },
fileFieldName: 'file',
});Posts link-based media payload.
await api.uploadLink('/media/from-link', 'https://example.com/image.jpg', {
folder: 'imports',
});Chunked/resumable upload with progress and retries.
await api.uploadResumable('/upload/chunk', {
file: { uri: 'file:///tmp/video.mp4', name: 'video.mp4', type: 'video/mp4' },
chunkSize: 2 * 1024 * 1024,
maxRetriesPerChunk: 3,
onProgress(p) {
console.log(p.progress);
},
finalizeEndpoint: '/upload/finalize',
});Invalidate cache entries by prefix scope.
Clear all cache entries.
Drop pending offline queued requests.
All thrown errors are normalized:
{
message: string;
status: number;
data?: unknown;
originalError?: unknown;
}