enhanced_http 4.2.2 copy "enhanced_http: ^4.2.2" to clipboard
enhanced_http: ^4.2.2 copied to clipboard

A wrapper around the dart http package provided by Google which is inspired by axios

enhanced-http #

Pub GitHub license

A wrapper around the dart http package provided by Google (https://pub.dev/packages/http) which is inspired by axios

Getting started #

Create an instance of enhanced http as follows :

EnhancedHttp http = EnhancedHttp(baseURL: "https://dog.ceo/api");

Custom headers can be provided through the name parameter 'headers' ( Default content type is specified as application/json ) :

EnhancedHttp http = EnhancedHttp(
  baseURL: "https://dog.ceo/api",
  headers: {'Authorization': "Bearer $token"}
);

Provide optional interceptors as follows :

EnhancedHttp http = EnhancedHttp(
    baseURL: "https://dog.ceo/api",
    interceptors: InterceptorOptions(
      response: (dynamic res) {
        print("Status ${res["status"]}");
        print("Headers ${res["headers"]}");
        print("Data ${res["data"]}");
        return res["data"];
      },
      error: (dynamic e) {
        print(e);
        return "An error has occurred please try again later";
      }
    )
);

Usage #

Fetch data from an api endpoint - GET

final res = await http.get("/path");

Send data to an api endpoint - POST

final res = await http.post("/path", payload: {
    "data": "This is some sample data to send to a server"
});

Update data at an api endpoint - PUT

final res = await http.put("/path", payload: {
    "data": "This is some sample data to update at a server"
});

Partially update data at an api endpoint - PATCH

final res = await http.put("/path", payload: {
    "data": "This is some sample data to update at a server"
});

Delete data at an api endpoint - DELETE

final res = await http.delete("/path");

Request headers at an api endpoint - HEAD

final res = await http.head("/path");

Additional Parameters #

The files attribute on the http post, http put and http patch methods can be used to send files to the server

final res = await http.post("/path",
    payload: {
        "data": "This is some sample data to update at a server"
    },
    headers: {
      "Content-Type": "multipart/form-data"
    },
    files: [
        {
            "array_key": "file",
            "file": File("path_to_file")
        }
    ],
);

Access to the underlying http package #

The underlying http package can be accessed as follows bypassing the transitive dependency import warning:

import 'package:enhanced_http/enhanced_http.dart' as http;

final res = await http.get("/path");
5
likes
160
pub points
54%
popularity

Publisher

verified publishersliitfoss.org

A wrapper around the dart http package provided by Google which is inspired by axios

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http, http_parser, path

More

Packages that depend on enhanced_http