api_utils 0.0.1

Flutter Android iOS web

Simple api utilities to make working with REST easier

Api Utils for Dart & Flutter #

ain't no REST for the wicked

Intro #

A collection of helper functions and an ApiResponse class that make working with REST apis a bit easier.

Usage #

Here is an example of making a GET to an endpoint that returns a list.

All you need is a model with a fromJson contructor. This ensures you app only interacts with strongly typed models, not raw JSON lists and maps.

var response = await getList(
    url: 'https://jsonplaceholder.typicode.com/posts',
    fromJson: (x) => Post.fromJson(x),
);

Similarly for POST

var newPost = Post(title: 'title', body: 'body');
var response = await post(
    url: 'https://jsonplaceholder.typicode.com/posts',
    body: newPost.toJson(),
);

Error Logging #

It can be helpful to have a single place to log errors to the console or to a logging service.

message will always be populated. exception and stack will be populated if an exception is thrown when making the request.

ApiLogger.onErrorMiddleware.add((message, exception, stack) {
    if (kReleaseMode) {
        // log to logging service
    } else {
        // log to console
    }
});
0
likes
90
pub points
51%
popularity

Publisher

homex.com

Simple api utilities to make working with REST easier

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, http, meta

More

Packages that depend on api_utils