network 0.3.0 copy "network: ^0.3.0" to clipboard
network: ^0.3.0 copied to clipboard

outdated

Package including hooks for easy works with http package in dart

Logo

Package including hooks for easy works with http package in dart.

Pub

Key FeaturesGetting StartedTodoCredits

Key Features #

  • Simple hooks for get / post
  • Specify response type (blob\json api)

Getting Started #

Get request to API:

main() async {
  final getResponse = await network.get<network.JsonApiResponse>(
      'https://jsonplaceholder.typicode.com/todos/1');
  print(getResponse.toMap['title']);
}

Get request Blob:

main() async {
  final blobResponse = await network.get(
      'https://via.placeholder.com/300');
  print(blobResponse.bytes);
}

Post request to API:

final postResponse = await network.post<network.JsonApiResponse>(
      'https://jsonplaceholder.typicode.com/todos',
      body: {'title': 'test'});
  print(postResponse.toMap['id']);

Handle exceptions:

try {
  await network.get('https://jsonplaceholder.typicode.com/todos/202');
} on network.NetworkException catch (error) {
  print('Network exception called, status code: ${error.code}');
}

Provide their exceptions:

network.NetworkSettings().exceptionDelegate = (network.NetworkException error) {
  // You can check type of respose in error by:
  // if (error is network.JsonApiResponse)

  switch (error.code) {
    case 400:
      throw BadRequestException(error.response);
    case 404:
      throw NotFoundException(error.response);
    default:
      throw error;
  }
};

And... api reference available here

TODO #

  • Get
  • Post
  • Delete
  • Put
  • Decorators (#1)

Credits #

This software uses the following open source packages:

11
likes
0
pub points
67%
popularity

Publisher

verified publisherserge.software

Package including hooks for easy works with http package in dart

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

http

More

Packages that depend on network