Skip to content

Commit 59c4261

Browse files
Copilotfarfromrefug
andcommitted
Add comprehensive documentation for API improvements and streaming downloads
Agent-Logs-Url: https://github.com/nativescript-community/https/sessions/99200ca0-c02e-437d-bbdc-d3c5f6f221c3 Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
1 parent 1e2e3f7 commit 59c4261

File tree

3 files changed

+441
-12
lines changed

3 files changed

+441
-12
lines changed

docs/ALAMOFIRE_MIGRATION.md

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Since Alamofire doesn't expose its APIs to Objective-C (no @objc annotations), w
3434
- Handles all HTTP requests (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
3535
- Manages upload/download progress callbacks
3636
- Handles multipart form data uploads
37+
- **NEW: Streaming downloads** for memory-efficient file downloads
38+
- Clean, simplified API method names
3739
- Implements error handling compatible with AFNetworking
3840

3941
#### SecurityPolicyWrapper.swift
@@ -61,15 +63,20 @@ The TypeScript implementation in `src/https/request.ios.ts` was updated to use t
6163
- Replaced `AFMultipartFormData` with `MultipartFormDataWrapper`
6264
- Updated serializer references to use wrapper properties
6365
- Added error key constants for AFNetworking compatibility
66+
- **NEW:** Simplified method names for cleaner API
67+
- **NEW:** Added `downloadFilePath` option for streaming downloads
6468

6569
**Key changes:**
6670
- Manager initialization: `AlamofireWrapper.alloc().initWithConfiguration(configuration)`
6771
- Security policy: `SecurityPolicyWrapper.defaultPolicy()`
6872
- SSL pinning: `SecurityPolicyWrapper.policyWithPinningMode(AFSSLPinningMode.PublicKey)`
73+
- HTTP requests: `manager.request(method, url, params, headers, uploadProgress, downloadProgress, success, failure)`
74+
- Multipart uploads: `manager.uploadMultipart(url, headers, formBuilder, progress, success, failure)`
75+
- Streaming downloads: `manager.downloadToFile(url, destinationPath, headers, progress, completionHandler)`
6976

70-
## Feature Preservation
77+
## Feature Preservation & Enhancements
7178

72-
All features from the AFNetworking implementation have been preserved:
79+
All features from the AFNetworking implementation have been preserved and enhanced:
7380

7481
### ✅ Request Methods
7582
- GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
@@ -114,11 +121,51 @@ All features from the AFNetworking implementation have been preserved:
114121
- Raw data responses
115122
- Image conversion (UIImage)
116123
- File saving
124+
- **NEW: Streaming downloads** for memory-efficient large file handling
117125
- Error handling with status codes
118126

127+
## New Features
128+
129+
### Streaming Downloads
130+
The new `downloadFilePath` option enables memory-efficient downloads by streaming directly to disk:
131+
132+
```typescript
133+
import { request } from '@nativescript-community/https';
134+
135+
// Option 1: Use downloadFilePath in request options
136+
const response = await request({
137+
method: 'GET',
138+
url: 'https://example.com/large-file.zip',
139+
downloadFilePath: '/path/to/save/file.zip',
140+
onProgress: (current, total) => {
141+
console.log(`Downloaded ${current} of ${total} bytes`);
142+
}
143+
});
144+
145+
// Option 2: Traditional toFile() still works but loads into memory first
146+
const response = await request({
147+
method: 'GET',
148+
url: 'https://example.com/file.zip'
149+
});
150+
const file = await response.content.toFile('/path/to/save/file.zip');
151+
```
152+
153+
**Benefits of streaming downloads:**
154+
- No memory overhead for large files
155+
- Better performance on memory-constrained devices
156+
- Progress tracking during download
157+
- Automatic file path creation
158+
159+
### Cleaner API Methods
160+
All Swift wrapper methods now use simplified, more intuitive names:
161+
- `request()` instead of `dataTaskWithHTTPMethod...`
162+
- `uploadMultipart()` instead of `POSTParametersHeaders...`
163+
- `uploadFile()` instead of `uploadTaskWithRequestFromFile...`
164+
- `uploadData()` instead of `uploadTaskWithRequestFromData...`
165+
119166
## API Compatibility
120167

121-
The TypeScript API remains **100% compatible** with the previous AFNetworking implementation. No changes are required in application code that uses this plugin.
168+
The TypeScript API remains **100% compatible** with the previous AFNetworking implementation. No changes are required in application code that uses this plugin. New features are opt-in through additional options.
122169

123170
## Testing Recommendations
124171

@@ -139,7 +186,13 @@ After upgrading, test the following scenarios:
139186
- Multiple files in multipart form
140187
- Large file uploads with progress tracking
141188

142-
4. **Progress Callbacks**
189+
4. **File Downloads**
190+
- Small file downloads (traditional method)
191+
- Large file downloads with streaming (using `downloadFilePath`)
192+
- Progress tracking during downloads
193+
- Memory usage with large files
194+
195+
5. **Progress Callbacks**
143196
- Upload progress for large payloads
144197
- Download progress for large responses
145198

0 commit comments

Comments
 (0)