http_helper 1.0.4 copy "http_helper: ^1.0.4" to clipboard
http_helper: ^1.0.4 copied to clipboard

The http_helper is a powerful yet easy-to-use HTTP networking library for Dart, designed to encapsulate the complexities of making HTTP requests in client applications.

example/http_helper_example.dart

import 'package:http_helper/http_helper.dart';

import 'typicode_model_example.dart';

void main() async {
// Define the URL, path, headers and query parameters
  String url = 'jsonplaceholder.typicode.com';
  String path = '/posts';
  Map<String, String> headers = {"Authorization": "Bearer your_token_here"};
  Map<String, dynamic> queryParams = {
    "userId": 1,
    "title": "Test Title",
    "body": "Test Body"
  };

// Make a POST request
  var response = await HttpHelper.makeRequest<TypicodeModel>(url, path,
      HttpRequestMethod.post, (response) => TypicodeModel.fromJson(response),
      headers: headers, queryParameters: queryParams);

  print(response.statusCode);

// Print the response data
  if (response.isSuccess) {
    print(response.data);
  } else {
    // Note: when not response.isSuccess, error and message will never be null, so it is save to access them!
    print(response.error!.message!);
  }
}
9
likes
0
pub points
27%
popularity

Publisher

unverified uploader

The http_helper is a powerful yet easy-to-use HTTP networking library for Dart, designed to encapsulate the complexities of making HTTP requests in client applications.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, json_annotation, json_serializable

More

Packages that depend on http_helper