A SUPER-LIGHT HTTP REQUEST UTIL
PS: Chinese-Readme in ReadMe-CH.md file
YOU CAN SEE DEMO IN FISHHTTP--DEMO--GET
This http request use Annotation & Builder mode to configure request params, so is more easily to use
For android studio developers
After:
1.Download or git clone this module in your project dir.
2.Open settings.gradle add ":fishhttp" behind include ':app' and etc. use comma to separate them
3.Open module setting -> your module which use http util ->Dependencies -> module dependency :fishhttp
4.add uses-permission :
android.permission.INTERNET
android.permission.READ_PHONE_STATE
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
5.In build.gradle of the Project: in node:buildscript -> dependencies
add classpath 'me.tatarka:gradle-retrolambda:3.2.5' to support lambda exp.
Start use it
1.Create a RequestHelper entity~ like this:
@NetMethod(GET or POST)
@NetUrl(your connect url)
@Result(will trans the response json to this class)
RequestHelper request
And MUST CALL NetInject to inject annotations to this class before use this entity~~~
PS: the generate type will as callback param giving you~
2.if you need url params, you can use the method:
request.UrlParam(Serializable object) -> it returns request self so you can use "." continue~
3. if use post request and need add body params, use this method:
request.PostParam(Serializable object) it seems like add url param~
4. you can add callback when the request is success or failed
AND THE CODES WILL RUN IN MAIN THREAD!
request.Success(Done done).Failed(Done msg);
you can use lambda-exp. like this:
request.Success((result) -> {DO SUCCESS WITH result entity})
.Failed((msg) -> {DO FAILED WITH msg entity})
finally, you only need call request.post/get(Context, Handler) to start http request~~
Happy to send email to me with suggestions or just chat with me~~~
email: [email protected]
UPDATE 0.2
REMOVE BaseEntity Type limit of Request result~
UPDATE 0.3
fix a bug : url params adder bug~
support add header properties;
add url param appender:
1.UrlParam(REQEST_PARAMS, Boolean isFirst)
2.UrlParam(Key,Value,Boolean isFirst)
3.UrlParam(REQEST_PARAMS) -> default: UrlParam(REQEST_PARAMS, true),used for single param bean;
4.UrlParam(Key,Value) -> default: UrlParam(Key,Value,false), used for param append quickly~
UPDATE 0.4
Change POST request and FIX BUGS in POST METHOD!
Support for 'application/x-www-form-urlencoded' and 'application/json' in 2 different API
The API of add body-parameters:
application/x-www-form-urlencoded use: PostParam(Serializable obj) returns RequestHelper
application/json use : PostJson(Object obj) returns RequestHelper
My POST METHOD server may be not open usually~ so you can use post server of your corp.
And Come in My QQ GROUP for discussion~~
UPDATE 0.5
Fix BUGS in NetInject (NP Exception QwQ)
Post parameter adder can be used with key-value (default:NOT first)
Add TypeToken setter while using List Generic type, U can try TypeToken instead of using Result (class)
Add sync-post/get request method to keep sync~
UPDATE 0.51
Fix bug: A bug of OKHttp: post chinese word will be crashed.
UPDATE 1.0
Add upload single file/image file support.
Using postSingle* Method, PostParam will be not enable.
UPDATE 1.01
FIX ONE BUG, using UrlParam will add multiple when isFirst=true
UPDATE 1.1
NEEDN'T EDIT GRADLE FILES, SUPPORT HTTPS, TLS 2-WAY-AUTH SUPPORTS, REFACTOR CODES