iws_http 1.2.0
iws_http: ^1.2.0 copied to clipboard
Library to facilitate http requests with error handling for Rest API requests.
example/main.dart
// ignore_for_file: avoid_print
import 'package:iws_http/iws_http.dart';
void main() async {
// Initialize IwsHttp singleton
final iwsHttp = IwsHttp.setup(
authority: 'jsonplaceholder.typicode.com',
basePath: '/',
defaultAuth: false, // Public API, does not require JWT Bearer token
);
try {
// Perform a GET request to /posts/1
final response = await iwsHttp.get(
path: 'posts/1',
);
// response is already decoded from JSON to Map<String, dynamic>
print('Post title: ${response['title']}');
print('Post body: ${response['body']}');
} on ApiException catch (e) {
print('Request failed with HTTP status ${e.httpCode}: ${e.error}');
}
}