http_request_f 0.0.2 copy "http_request_f: ^0.0.2" to clipboard
http_request_f: ^0.0.2 copied to clipboard

The http_request_f package simplifies HTTP request operations in Dart and Flutter

"The http_request_f package simplifies HTTP request operations in Dart and Flutter. Our package allows you to perform HTTP requests, automatically handle JSON serialization and deserialization, and conduct various URI operations, all using a single function

Features #

Simplified HTTP Requests: Make HTTP GET, POST, PUT, DELETE, and other requests with a single, straightforward function call. Streamlined JSON Handling: Our package automates JSON serialization and deserialization, enabling you to work directly with Dart objects. Effortless URI Manipulation: Easily manage URI operations, including building, modifying, and handling URL parameters. Customization: Customize requests by adding headers, cookies, and other parameters tailored to your use case. Easy Response Handling: Obtain HTTP responses and process them effortlessly, whether they contain JSON, text, or other formats.

Getting started #

import 'package:http_request_f/http_request_f.dart';
import 'package:http_request_f/request_status/error_type.dart';
void main() async {
  final HttpRequest httpRequest =
      HttpRequest(baseUrl: "https://jsonplaceholder.typicode.com");

  //get Request
  try {
    final jsonResponse = await httpRequest.init(
        path: "posts", requestType: RequestType.get); //decoded data
    print(jsonResponse);

    for (var element in jsonResponse) {
      print("element ${element['id']} - ${element['title']}");
    }
  } catch (e) {
    print(ErrorType.get(e));
  }
}

Usage #

import 'package:http_request_f/http_request_f.dart';
import 'package:http_request_f/request_status/error_type.dart';

final HttpRequest httpRequest =
      HttpRequest(baseUrl: "https://jsonplaceholder.typicode.com");
void main() async {


  //get Request
  try {
    final jsonResponse = await httpRequest.init(
        path: "posts", requestType: RequestType.get); //decoded data
    print(jsonResponse);

    for (var element in jsonResponse) {
      print("element ${element['id']} - ${element['title']}");
    }
  } catch (e) {
    print(ErrorType.get(e));
  }
  //post Request
  try {
    Map<String, dynamic> body = {
      "title": 'foo',
      "body": 'bar',
      "userId": 1,
    };
    final response = await httpRequest.init(
        path: "posts", requestType: RequestType.post, body: body);
    print(response);
  } catch (e) {
    print(ErrorType.get(e));
  }
  //put and patch Request

  try {
    Map<String, dynamic> body = {
      "title": 'foo',
      "body": 'bar',
      "userId": 1,
    };
    final response = await httpRequest.init(
        path: "posts/1",
        requestType: RequestType.put,
        body: body); // use RequestType.put or RequestType.patch
    print(response);
  } catch (e) {
    print(ErrorType.get(e));
  }
  //delete Request

  try {
    final response = await httpRequest.init(
      path: "posts/1",
      requestType: RequestType.delete,
    );
    print(response);
  } catch (e) {
    print(ErrorType.get(e));
  }
  //set token
  Future<bool> tokenSet = httpRequest.setAuthToken(
      token:
          "your-token"); // the default token type is Bearer and this token is automaticaly added to to headers to perform requests
}

Additional information #

5
likes
0
points
57
downloads

Publisher

unverified uploader

Weekly Downloads

The http_request_f package simplifies HTTP request operations in Dart and Flutter

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, http, http_parser, shared_preferences

More

Packages that depend on http_request_f