Difference over other Networking Library
- In Fast Android Networking Library, OkHttpClient can be customized for every request easily.
- As Fast Android Networking Library uses OkHttp and Okio, it is faster.
- Single library for all type of networking.
- Supports RxJava, RxJava2 -> Check here
- Current bandwidth and connection quality can be obtained to decide logic of code.
- Executor can be passed to any request to get response in another thread.
- Complete analytics of any request can be obtained.
- All types of customization is possible.
- Immediate Request is really immediate now.
- Prefetching of any request can be done so that it gives instant data when required from cache.
- Proper cancellation of request.
- Do not cancel a request if completed more than a threshold percentage.
- Simple interface to make any type of request.
- Proper Response Caching, hence reducing bandwidth usage.
Fast Android Networking Library
About Fast Android Networking Library
Fast Android Networking Library is a powerful library for doing any type of networking in Android applications which is made on top of OkHttp Networking Layer.
Fast Android Networking Library takes care of each and everything. So you don’t have to do anything, just make request and listen for the response.
Why use Fast Android Networking ?
- Recent removal of HttpClient in Android Marshmallow(Android M) made other networking library obsolete.
- No other single library do each and everything like making request, downloading any type of file, uploading file, loading
image from network in ImageView, etc. There are libraries but they are outdated. - No other library provided simple interface for doing all types of things in networking like setting priority, cancelling, etc.
- As it uses Okio , No more GC overhead in android application.
Okio is made to handle GC overhead while allocating memory.
Okio do some clever things to save CPU and memory. - As it uses OkHttp , most important it supports HTTP/2.
RxJava2 Support, check here.
RxJava2 + Fast Android Networking + Dagger2 with MVP Architecture Project, Check here
Another awesome library for debugging databases and shared preferences, Check here
Find this project useful ? :heart:
- Support it by clicking the :star: button on the upper right of this page. :v:
For full details, visit the documentation on our web site :
Requirements
Fast Android Networking Library can be included in any Android application.
Fast Android Networking Library supports Android 2.3 (Gingerbread) and later.
Using Fast Android Networking Library in your application
Add this in your build.gradle
Do not forget to add internet permission in manifest if already not present
Then initialize it in onCreate() Method of application class :
Initializing it with some customization , as it uses OkHttp as networking layer, you can pass custom okHttpClient while initializing it.
Using the Fast Android Networking with Jackson Parser
|
|
Making a GET Request
|
|
Making a POST Request
|
|
You can also post java object, json, file, etc in POST request like this.
Using it with your own JAVA Object - JSON Parser
|
|
Downloading a file from server
|
|
Uploading a file to server
|
|
Getting Response and completion in an another thread executor
(Note : Error and Progress will always be returned in main thread of application)
Setting a Percentage Threshold For Not Cancelling the request if it has completed the given threshold
|
|
Cancelling a request.
Any request with a given tag can be cancelled. Just do like this.
Loading image from network into ImageView
|
|
Getting Bitmap from url with some specified parameters
|
|
Error Code Handling
|
|
Remove Bitmap from cache or clear cache
|
|
Prefetch a request (so that it can return from cache when required at instant)
|
|
Customizing OkHttpClient for a particular request
|
|
Making a conditional request (Building a request)
|
|
ConnectionClass Listener to get current network quality and bandwidth
|
|
Getting Analytics of a request by setting AnalyticsListener on that
|
|
Getting OkHttpResponse in Response
|
|
Making Synchronous Request
|
|
How caching works ?
- First of all the server must send cache-control in header so that is starts working.
- Response will be cached on the basis of cache-control max-age,max-stale.
- If internet is connected and the age is NOT expired it will return from cache.
- If internet is connected and the age is expired and if server returns 304(NOT MODIFIED) it will return from cache.
- If internet is NOT connected if you are using getResponseOnlyIfCached() - it will return from cache even it date is expired.
- If internet is NOT connected , if you are NOT using getResponseOnlyIfCached() - it will NOT return anything.
- If you are using getResponseOnlyFromNetwork() , it will only return response after validation from server.
- If cache-control is set, it will work according to the max-age,max-stale returned from server.
- If internet is NOT connected only way to get cache Response is by using getResponseOnlyIfCached().
Enabling Logging
|
|
Enabling GZIP From Client to Server
|
|
IMPORTANT NOTE
- Use IMMEDIATE Priority with caution - use is at appropriate place only when
1 or 2 (at max 2)IMMEDIATE request is required at instant.Otherwise use HIGH Priority. Known Bug : As present if you are using GZIP Interceptor from client to server, Upload progress
is not working perfectly in Multipart.If you are using Proguard with Gradle build system (which is usually the case), you don’t have to do anything. The appropriate Proguard rules will be automatically applied. If you still need the rules applied in
proguard-rules.pro
, it is as follows:1-dontwarn okio.**
Fast Android Networking Library supports
- Fast Android Networking Library supports all types of HTTP/HTTPS request like GET, POST, DELETE, HEAD, PUT, PATCH
- Fast Android Networking Library supports downloading any type of file
- Fast Android Networking Library supports uploading any type of file (supports multipart upload)
- Fast Android Networking Library supports cancelling a request
- Fast Android Networking Library supports setting priority to any request (LOW, MEDIUM, HIGH, IMMEDIATE)
- Fast Android Networking Library supports RxJava
As it uses OkHttp as a networking layer, it supports:
- Fast Android Networking Library supports HTTP/2 support allows all requests to the same host to share a socket
- Fast Android Networking Library uses connection pooling which reduces request latency (if HTTP/2 isn’t available)
- Transparent GZIP shrinks download sizes
- Fast Android Networking Library supports response caching which avoids the network completely for repeat requests
Difference over other Networking Library
- In Fast Android Networking Library, OkHttpClient can be customized for every request easily.
- As Fast Android Networking Library uses OkHttp and Okio, it is faster.
- Single library for all type of networking.
- Supports RxJava, RxJava2 -> Check here
- Current bandwidth and connection quality can be obtained to decide logic of code.
- Executor can be passed to any request to get response in another thread.
- Complete analytics of any request can be obtained.
- All types of customization is possible.
- Immediate Request is really immediate now.
- Prefetching of any request can be done so that it gives instant data when required from cache.
- Proper cancellation of request.
- Do not cancel a request if completed more than a threshold percentage.
- Simple interface to make any type of request.
- Proper Response Caching, hence reducing bandwidth usage.
TODO
- Integration with other library
- And of course many many features and bug fixes
CREDITS
- Square - As both OkHttp and Okio
used by Fast Android Networking is developed by Square. - Volley - As Fast Android Networking uses ImageLoader that is developed by Volley.
- Prashant Gupta - For RxJava, RxJava2 Support - RxJava Support
###Check out Mindorks awesome open source projects here
Contact - Let’s become friend
License
|
|
Contributing to Fast Android Networking
Just make pull request. You are in!