@liter
2015-11-10T15:15:55.000000Z
字数 3808
阅读 2969
litehttp2.x-tutorials
Website : http://litesuits.com
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code!
It could convert a java model to the parameter and rander the response JSON as a java model intelligently.
Simple, powerful, make HTTP request with only one line of code:
User user = liteHttp.get (url, User.class);
asynchronous download a file(execute on sub-thread,listen on ui-thread):
liteHttp.executeAsync(new FileRequest(url,path).setHttpListener(
new HttpListener<File>(true, true, true) {
@Override
public void onLoading(AbstractRequest<File> request, long total, long len) {
// loading notification
}
@Override
public void onSuccess(File file, Response<File> response) {
// successfully download
}
})
);
configure an asynchronous login request by annotation:
String loginUrl = "http://litesuits.com/mockdata/user_get";
// 1. URL : loginUrl
// 2. Parameter : name=value&password= value
// 3. Response : User
@HttpUri(loginUrl)
class LoginParam extends HttpRichParamModel<User> {
private String name;
private String password;
public LoginParam(String name, String password) {
this.name = name;
this.password = password;
}
}
liteHttp.executeAsync(new LoginParam("lucy", "123456"));
will be built as http://xxx?name=lucy&password=123456
more details, you can see lite-http introduction: LiteHttp Introduction: Why should developers choose LiteHttp ?
Lightweight: tiny size overhead to your app. About 99kb for core jar. .
One-Thread-Based: all methods work on the same thread as the request was created.
Full support: GET, POST, PUT, DELETE, HEAD, TRACE, OPTIONS, PATCH.
Automatic: one line of code auto-complete translation between Model and Parameter, Json and Model.
Configurable: more flexible configuration options, up to 23+ items.
Polymorphic: more intuitive API, input and output is more clear.
Strong Concurrency: concurrent scheduler that comes with a strong, effective control of scheduling and queue control strategies.
Annotation Usage: convention over configuration. Parameters, Response, URL, Method, ID, TAG, etc. Can be configured.
Easy expansion: extend the abstract class DataParser to parse inputstream(network) to which you want..
Alternatively: interface-based, easy to replace the network connection implementations and Json serialization library.
Multilayer cache: hit Memory is more efficient! Multiple cache mode. Support for setting cache expire time.
Callback Flexible: callback can be on current or UI thread. listen the beginning, ending, success or failure, uploading, downloading, etc.
File Upload: support for single, multiple, large file uploads.
Downloads: support files, Bimtap download and progress notifications.
Network Disabled: disable one of a variety of network environments, such as specifying disabling 2G, 3G.
Statistics: time cost statistics and traffic statistics.
Exception system: a unified, concise, clear exception is thrown into three categories: client, network, server, and abnormalities can be accurately subdivided.
GZIP compression: automatic GZIP compression.
Automatic Retry: combined probe exception type and current network conditions, intelligent retry strategies.
Automatic redirection: based on the retry 30X state, and can set the maximum number of times to prevent excessive jump.
About App architecture, see my other article:
How to take high-quality Android project framework, the framework of the structure described in detail?
Good ◝‿◜, huh:
1. Initialization and preliminary usage
2. Simplified requests and non-safe method of use
4. Custom DataParser and Json serialization library Replace
5. Files, bitmap upload and download
6. Disable network and traffic statistics
8. Exceptions handling and cancellation request
9. Multiple data transmission via POST(PUT)
10. Asynchronous concurrency and scheduling strategy
11. Global configuration and parameter settings Detailed
13. Multilayer cache mechanism and usage