super simple library to manage http requests.
dependencies {
compile 'com.studioidan.httpagent:httpagent:1.0.10@aar'
}
HttpAgent.get("www.example.com/api/books")
.goJson(new JsonCallback() {
@Override
protected void onDone(boolean success, JSONObject jsonObject) {
}
});
or you can go jsonArray like so
HttpAgent.get("www.example.com/api/books")
.goJsonArray(new JsonArrayCallback() {
@Override
protected void onDone(boolean success, JSONArray jsonArray) {
}
});
HttpAgent.get("www.example.com/api/books")
.queryParams("key_1","value_1","key_2","value_2","key_N","value_N")
.goJsonArray(new JsonArrayCallback() {
@Override
protected void onDone(boolean success, JSONArray jsonArray) {
}
});
HttpAgent.post("www.example.com/api/books");
HttpAgent.put("www.example.com/api/books");
HttpAgent.delete("www.example.com/api/books")
HttpAgent.post("www.example.com/api/books")
.queryParams("key_1","value_1","key_2","value_2","key_N","value_N")
.withBody("{name:popapp ,age:27}")
.goJsonArray(new JsonArrayCallback() {
@Override
protected void onDone(boolean success, JSONArray jsonArray) {
}
});
HttpAgent.get("http://192.168.88.253/Video/inputs/channels/1")
.headers("Authorization", "Basic YWRtaW46P3V5YFZhNzAw", "Content-Type", "application/json")
.goString(new StringCallback() {
@Override
protected void onDone(boolean success, String stringResults) {
Log.d(TAG, stringResults);
}
});
goString(new StringCallback() {
@Override
protected void onDone(boolean success, String results) {
}
})
goJson(new JsonCallback() {
@Override
protected void onDone(boolean success, JSONObject jsonObject) {
}
})
goJsonArray(new JsonArrayCallback() {
@Override
protected void onDone(boolean success, JSONArray jsonArray) {
}
});
go(new SuccessCallback() {
@Override
protected void onDone(boolean success) {
}
})
HttpAgent.post("www.example.com/api/books")
.queryParams("key_1","value_1","key_2","value_2","key_N","value_N")
.withBody("{name:popapp ,age:27}")
.goJson(new JsonCallback() {
@Override
protected void onDone(boolean success, JSONObject jsonObject) {
getErrorMessage(); //returns error message if exists.
getResponseCode(); // well, it's obvious...
getStringResults(); // returns results as as string.
}
});