asis 0.0.1 asis: ^0.0.1 copied to clipboard
A small utility library to handle http responses easily.
asis #
A small utility library to handle JSON decoded http responses with ease by transforming them into internal data types.
Getting Started #
This package built upon the dart http package to work with it's internal Response type, but some useful internal features can be used without it, such as List.as<T>
, Future<List<T>>.as<T>
, Future<List<T>>.map<T>
, etc...
Examples #
/// Get a single task and transform it into the internal Task type.
Task task = await http.get('...')
.as<Task>((e) => Task.fromJson(e));
/// Get all tasks as an iterable internal list of tasks.
List<Task> tasks = await http.get('...')
.asListOf<Task>((e) => Task.fromJson(e));
/// Get all titles from tasks.
List<String> title = await http.get('...')
.asList
.as<String>((e) => e.title);
/// Get all tasks as a List<Task>, and modify it on the same future chain.
List<Tasks> tasks = await http.get('...')
.asListOf<Task>((e) => Task.fromJson(e))
.then((list) => list.take(3))
.then((iterable) => iterable.toList());
/// A simple handler that returns a Task.
Task taskHandler(dynamic e) => Task(e['key']);
List<Task> tasks = await http.get(url)
.asListOf<Task>(taskHandler);