iws_http_model 0.6.2 copy "iws_http_model: ^0.6.2" to clipboard
iws_http_model: ^0.6.2 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}.');
  }
}
0
likes
150
points
31
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Library for HTTP requests with the common operations CRUD, pagination and error handling.

Homepage

License

MIT (license)

Dependencies

flutter, iws_http

More

Packages that depend on iws_http_model