HttPizza

Additional

Language
Java
Version
0.3.0 (Feb 13, 2016)
Created
Feb 2, 2016
Updated
Feb 24, 2016 (Retired)
Owner
Dino Kovač (reisub)
Contributor
Dino Kovač (reisub)
1
Activity
Badge
Generate
Download
Source code

Advertisement

HttPizza

![Method count](https://img.shields.io/badge/Methods count-365-e91e63.svg)

Lightweight HTTP client using HttpURLConnection under the hood. The primary use case is for apps, libraries and SDKs which don't need/want all the features (and methods!) OkHttp provides.

It has the same limitations as HttpURLConnection like not supporting the PATCH method and not permitting request body in DELETE requests.

Usage

Add the library as a dependency to your build.gradle to automatically download it from jcenter.

compile 'sexy.code:httpizza:0.3.0'

We also maintain a changelog.

Create a client

HttPizza client = new HttPizza();

GET request

Request request = client.newRequest()
        .url(url)
        .get()
        .build();

Response response = client.newCall(request).execute();

POST request

Request request = client.newRequest()
        .url(url)
        .post(RequestBody.create(MediaType.parse("text/plain; charset=utf-8"), "requestBody"))
        .build();

Response response = client.newCall(request).execute();

Async GET request

Request request = client.newRequest()
        .url(url)
        .build();

client.newCall(request).enqueue(new Callback() {
    @Override
    public void onResponse(Response response) {
        if (response.isSuccessful()) {
            Timber.d("Body: %s", response.body().string());
        } else {
            Timber.d("Status code: %s", response.code());
        }
    }

    @Override
    public void onFailure(Throwable t) {
        Timber.e(t.getMessage());
    }
});

POST request with form parameters

RequestBody formBody = new FormBody.Builder()
        .add("search", "Airplane!")
        .build();

Request request = client.newRequest()
        .url(url)
        .post(formBody)
        .build();

Response response = client.newCall(request).execute();

Credits

HttPizza reuses parts of OkHttp and is largely based on lighthttp.

It also draws inspiration from OkHttp and Retrofit APIs.

Contributing

Feedback and code contributions are very much welcome. Just make a pull request with a short description of your changes. By making contributions to this project you give permission for your code to be used under the same license.