requestor 0.0.26
requestor: ^0.0.26 copied to clipboard
A Flutter package for making HTTP requests and downloading files efficiently.
Requestor Flutter Library #
Requestor is a library for making HTTP requests and downloading files in Flutter easily and efficiently.
Installation #
To use this library, add the following line to your pubspec.yaml file:
dependencies:
requestor: last_version
Then run the command flutter pub get to install the library.
Basic Usage #
Import the library in your Dart file:
import 'package:requestor/requestor.dart';
Create an instance of Requestor and configure it according to your needs:
Requestor requestor = Requestor();
requestor.setOrigin('https://api.example.com');
requestor.addInterceptor((headers) {
header["request-token"] = "xxxxxxx"; // example
return headers;
});
Making a GET Request
Response response = await requestor.get('/endpoint');
print(response.data);
Making a POST Request
Map<String, dynamic> data = {'key': 'value'};
Response response = await requestor.post('/endpoint', data);
print(response.data);
Downloading Files
List<DownloadItem> files = [
DownloadItem(url: 'https://example.com/file1.txt'),
DownloadItem(url: 'https://example.com/file2.txt'),
];
String outputPath = '/path/to/save/files';
await requestor.downloadFiles(files, output: outputPath);
Available Methods
- get(url, [headers]): Makes a GET request.
- post(url, data, [headers]): Makes a POST request.
- put(url, data, [headers]): Makes a PUT request.
- delete(url, [headers]): Makes a DELETE request.
- options(url, data, [headers]): Makes an OPTIONS request.
- patch(url, data, [headers]): Makes a PATCH request.
- downloadFiles(urls, {output, headers, threads, onProgress, onDownload}): Downloads files from a list of URLs.
- getApplicationPath(): Gets the application path.
- getFilesByDirectory(path): Gets a list of files in a specific directory.
Additional Configuration
You can configure the number of threads for downloads and add custom headers to requests.
requestor.threads = 10;
requestor.setConfig({'token': 'your_auth_token'});
And that's it! Now you are ready to start using the Requestor library in your Flutter application.