https://github.com/reisub/HttPizza
Lightweight HTTP client for Android apps
https://github.com/reisub/HttPizza
Last synced: 3 months ago
JSON representation
Lightweight HTTP client for Android apps
- Host: GitHub
- URL: https://github.com/reisub/HttPizza
- Owner: reisub
- License: apache-2.0
- Archived: true
- Created: 2016-02-01T19:53:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-23T21:33:36.000Z (over 10 years ago)
- Last Synced: 2023-05-27T14:25:18.541Z (about 3 years ago)
- Language: Java
- Size: 128 KB
- Stars: 52
- Watchers: 1
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-java - HttPizza
README
# HttPizza
[](https://www.apache.org/licenses/LICENSE-2.0)
[ ](https://bintray.com/reisub/maven/httpizza/_latestVersion)
[](http://www.methodscount.com/?lib=sexy.code%3Ahttpizza%3A0.3.0)
[](https://coveralls.io/github/reisub/HttPizza?branch=master)
Lightweight HTTP client using [HttpURLConnection](http://developer.android.com/intl/es/reference/java/net/HttpURLConnection.html) under the hood.
The primary use case is for apps, libraries and SDKs which don't need/want all the features ([and methods!](http://www.methodscount.com/?lib=com.squareup.okhttp3%3Aokhttp%3A3.0.1)) 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.
```groovy
compile 'sexy.code:httpizza:0.3.0'
```
We also maintain a [changelog](CHANGELOG.md).
### Create a client
```java
HttPizza client = new HttPizza();
```
### GET request
```java
Request request = client.newRequest()
.url(url)
.get()
.build();
Response response = client.newCall(request).execute();
```
### POST request
```java
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
```java
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
```java
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](https://github.com/square/okhttp) and is largely based on [lighthttp](https://github.com/satorufujiwara/lighthttp).
It also draws inspiration from [OkHttp](https://github.com/square/okhttp) and [Retrofit](https://github.com/square/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](LICENSE).