enhanced_http 3.1.2 copy "enhanced_http: ^3.1.2" to clipboard
enhanced_http: ^3.1.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: Constants.apiBaseURL,
  headers: {'Authorization': "Bearer $token"}
);

Provide optional interceptors as follows :

EnhancedHttp http = EnhancedHttp(
    baseURL: Constants.apiBaseURL,
    interceptors: {
      "response": (res) {
        print("Status ${res["status"]}");
        print("Headers ${res["headers"]}");
        print("Data ${res["data"]}");
        return res["data"];
      },
      "error": (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")
        }
    ],
);
5
likes
0
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

License

unknown (license)

Dependencies

flutter, http, http_parser, path

More

Packages that depend on enhanced_http