simple_http_client 0.9.0

  • Installing
  • Versions
  • new47


A flexible Http Client for Flutter and Dart Server. Built on top of dart:io, SimpleHttpClient adds many features that are commonly used like interceptors or authenticators.


Making requests using simple_web_client is very straightforward.


To perform a GET request you can simply do:

SimpleHttpClient client = new SimpleHttpClient();

Response response = await client.get("");


POST is very similar to GET, but requires sending a String of the body.

SimpleHttpClient client = new SimpleHttpClient();
Response response =  await"", "{\"name\": \"asd\"}");


The four supported methods allow you to optionally specify the headers that will be sent.

SimpleHttpClient client = new SimpleHttpClient();

Response response = await client.get("",
    headers: {"x-test": "helloWorld"});


You can define the userAgent of your application by using the optional parameter of the constructor with the same name.

SimpleHttpClient client = new SimpleHttpClient(userAgent: "myAwesomeApp");

Request Interceptors

Often you want to intercept the requests before they are dispatched. For example, to set a recurring header. Notice that the interceptors will be called in the same order in which they are added to the client.

SimpleHttpClient client = new SimpleHttpClient();

client.addInterceptor((HttpClientRequest request) async {
  request.headers.set("X-Api-Token", "mySecretToken");

// This request will be intercepted
Request request = await client.get("");


This is a special interceptor that will be called upon a request receiving a 401 response from the server. If the server returns a 401 and there's no authenticator, a UnauthorizedException will be thrown.

SimpleHttpClient client = new SimpleHttpClient();

client.setAuthenticator((request) async{
  // Retrieve a new token
  String token = (await client.get("http://get.token")).body;

  // Set the header
  request.headers.set("Authorization", token);

You can specify how many times the authenticator should be called before the UnauthorizedException is thrown.

// Call the authenticator up to two times, throw `UnauthorizedException` if
// there's a `401` after those two calls.
SimpleHttpClient client = new SimpleHttpClient(maxAuthRetries: 2);

Reading the Response

get(), post(), put(), and delete() return a Response object. This response contains the statusCode, body, and headers returned by the server.

Response response = await client.get("");

print(response.statusCode); // prints the code, e.g 200
print(response.body); // prints the body, e.g "Hello World"
print(response.headers); // prints the response headers

More examples

Check the file test/simple_client_test.dart for detailed examples of all the features.


0.9.0 - Dec 30, 2018

First public version of the lib


  • Support for interceptors
  • Support for authenticator
  • Basic requests returning the response
  • Basic GET, POST, PUT, and DELETE support
  • Timeout support
  • Redirection config support
  • TLS: config to accept any certificate
  • TLS: config to add a certificate to the trusted certs
  • Timeout, Unauthorized, and TLS Exceptions

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  simple_http_client: ^0.9.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:simple_http_client/simple_http_client.dart';
Version Uploaded Documentation Archive
0.9.0 Dec 30, 2018 Go to the documentation of simple_http_client 0.9.0 Download simple_http_client 0.9.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.10


Detected platforms: Flutter, other

Primary library: package:simple_http_client/simple_http_client.dart with components: io.

Maintenance issues and suggestions

Homepage URL does not exists. (-20 points)

We were unable to access at the time of the analysis.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use simple_http_client.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
mock_web_server >=4.0.0 <5.0.0
resource >=2.1.5 <3.0.0
test >=1.5.1 <2.0.0