iws_http_model 0.4.1
iws_http_model: ^0.4.1 copied to clipboard
Library for HTTP requests with the common operations CRUD, pagination and error handling.
example/main.dart
import 'package:iws_http/iws_http.dart';
import 'package:iws_http_model/iws_http_model.dart';
class BookSearch {
final String kind;
final String id;
final String etag;
BookSearch(this.kind, this.id, this.etag);
factory BookSearch.fromJson(Map<String, dynamic> json) =>
BookSearch(json["kind"], json["id"], json["etag"]);
static Map<String, dynamic> toJson(BookSearch model) =>
{"kind": model.kind, "id": model.id, "etag": model.etag};
}
void main() async {
IwsHttp.setup(authority: 'googleapis.com', basePath: 'books/v1/');
final bookProvider = IwsHttpModel<BookSearch>(
path: 'volumes',
iwsHttp: IwsHttp(),
toJson: BookSearch.toJson,
fromJson: BookSearch.fromJson,
resultAttribute: 'items');
try {
PaginatedData<BookSearch> result =
await bookProvider.fetchPaginated(queryParameters: {'q': '{http}'});
print('Number of books about http: ${result.meta.total}.');
} on ApiException catch (e) {
print('Request failed with status: ${e.httpCode}.');
}
}