Lightweitht HTTP client for Android.
- Simple HTTP client.
- Depends on Android(HttpUrlConnection) only.
- Execute asynchronously or can use with RxJava.
- Convert request and response.
Get a url.
LightHttpClient httpClient = new LightHttpClient();
Request request = httpClient.newRequest()
.url("https://api.github.com/users/satorufujiwara/repos")
.get()
.build();
Response<String> response = httpClient.newCall(request).execute();
String body = response.getBody();
Convert response to java object.
httpClient.setConverterProvider(new GsonConverterProvider());
Response<Repos> response = httpClient.newCall(request, Repos.class).execute();
Repos body = response.getBody();
Post json object.
httpClient.setConverterProvider(new GsonConverterProvider());
Item obj = new Item();
Request request = httpClient.newRequest()
.url(url)
.post(obj, Item.class)
.build();
Execute asynchronously.
httpClient.newCall(request, Repos.class)
.executeOn(AsyncExecutor.<Repos>provide())
.executeAsync(new AsyncCallback<Repos>() {
@Override
public void onResult(Response<Repos> response, Throwable e) {
}
});
Use with RxJava.
httpClient.newCall(request, Repos.class)
.executeOn(RxExecutor.<Repos>provide())
.asObservable()
.subscribeOn(Schedulers.io())
.subscribe();
dependencies {
compile 'jp.satorufujiwara:lighthttp:0.1.1'
}
Gson
compile 'jp.satorufujiwara:lighthttp-gson:0.1.1'
Async
compile 'jp.satorufujiwara:lighthttp-async:0.1.1'
RxJava
compile 'jp.satorufujiwara:lighthttp-rx:0.1.1'
- Multipart request body.
- Jackson converter.
- Jsonic converter.
- Sample app.
- Testing.
Satoru Fujiwara (satorufujiwara)
- Twitter satorufujiwara
- holly.wist@gmail.com
Other Projects
- recyclerview-binder
- Android Library for RecyclerView to manage order of items and multiple view types.
- material-scrolling
- Android library for material scrolling techniques.
Copyright 2015 Satoru Fujiwara
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.