simplehttpconnection 1.3.1 copy "simplehttpconnection: ^1.3.1" to clipboard
simplehttpconnection: ^1.3.1 copied to clipboard

discontinued

Best simple way to request data with Simplehttpconnection - by Nizwar

Simple HTTP Connection #

Simple HTTP Connection, a library that i made to help me request data from internet while i develop flutter app, so i think i wanted to share it here ☺ This library using Http, Made with love by Moch. Nizwar Syafuan

Let's Code! #

var url = "https://postman-echo.com/get"
ResponseHttp respHttp = await  HttpConnection.doConnection(url);
print("Status Code : ${respHttp.statusCode}");
print("Status Headers : ${respHttp.headers}");
print("Content : ${respHttp.content}");

You can convert it to JSON easily, just put asJson() after content and you are ready to go :)

...
//it will return null if content isn't valid to convert to json
print("Content : ${respHttp.content.asJson()}");
...

Now, you can also making multiple requests to the same server, just keep open a presisten connection like this

...
ResponseHttp respHttp = await httpConnection.connect(tryUrl, method: Method.post); 
httpConnection.close(); //Close, if you do not want to use it
...
httpConnection.initConnection();   ///You have to init the connection if you want to use it again
respHttp = await httpConnection.connect(tryUrl, method: Method.post); 
...
httpConnection.close();

Request Stuff #

Get #

Psst....i made GET request look fun!

...
///Get Request
Map<String, String> params = Map();
params["foo1"] = "bar1";
params["foo2"] = "bar2";
ResponseHttp respHttp =await  HttpConnection.doConnection(url, method: Method.get, body: params);
...

Post #

...
HttpConnection.doConnection(url, method: HttpConnection.post, body: params);
...

Put #

...
HttpConnection.doConnection(url, method: HttpConnection.put, body: params);
...

Patch #

...
HttpConnection.doConnection(url, method: HttpConnection.patch, body: params);
...

Delete #

...
HttpConnection.doConnection(url, method: HttpConnection.delete);
...

Encoding #

Default encoding is UTF8, you can change it of course

...
HttpConnection.doConnection(url, encoding: utf8);
...

Download #

Now you can download file from SimpleDownload in simpliest way :D Thanks to Eka Setiawan Saputra from Flutter Indonesia for inspiring me... Updated, now you can controll your download progress....

... 
SimpleDownload simpleDownload = SimpleDownload();
print(await simpleDownload.start(
    "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
    path: "D:", downloadProgress: (progress, count, max) {
    print("Downloading : " + progress.toString() + "%");
})); 
simpleDownload.pause();  //Pause your download
simpleDownload.resume(); //Resume your download 
simpleDownload.stop();   //Stop your download
...
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Best simple way to request data with Simplehttpconnection - by Nizwar

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

http, path

More

Packages that depend on simplehttpconnection