Description
Simplified android async HTTP client
OptimusHTTP alternatives and similar packages
Based on the "Network" category.
Alternatively, view OptimusHTTP alternatives based on common mentions on social networks and blogs.
-
android-async-http
An asynchronous, callback-based Http client for Android built on top of Apache's HttpClient libraries. -
AndroidAsync
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads. -
robospice
DISCONTINUED. Repo of the Open Source Android library : RoboSpice. RoboSpice is a modular android library that makes writing asynchronous long running tasks easy. It is specialized in network requests, supports caching and offers REST requests out-of-the box using extension modules. -
android-lite-http
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. -
Minimized API Service Library
Minimized API library which is used call the server request in andorid.
InfluxDB - Purpose built for real-time analytics at any scale.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of OptimusHTTP or a related project?
README
Android library that simplifies networking in android via an async http client. <!-- Bintray --> <!-- API --> <!-- Android Arsenal --> <!-- Android Dev Digest --> <!-- GitHub stars --> <!-- GitHub forks --> <!-- GitHub watchers --> <!-- Say Thanks! --> <!-- GitHub followers --> <!-- Twitter Follow -->
Also featured in [Awesome Android Newsletter #Issue 15 ]
Built with ❤︎ by Nishant Srivastava and contributors
Including in your project
OptimusHTTP is available in the Jcenter, so getting it as simple as adding it as a dependency
implementation 'com.github.nisrulz:optimushttp:{latest version}'
where {latest version}
corresponds to published version in
Usage
Setup your SERVER url
String SERVER = "http://uinames.com/api/";
Create an instance of the OptimusHTTP class
OptimusHTTP client = new OptimusHTTP(context);
Next if in debug stage, enable logs
client.enableDebugging();
Define parameters to be sent with the request
ArrayMap<String, String> params = new ArrayMap<>(); params.put("email", "[email protected]"); params.put("pass", "abc");
Define configurations for the request
- Type of Method : POST/GET
- POST Request
java client.setMethod(OptimusHTTP.METHOD_POST);
- GET Request
java client.setMethod(OptimusHTTP.METHOD_GET);
- PUT Request
java client.setMethod(OptimusHTTP.METHOD_PUT);
- DELETE Request
java client.setMethod(OptimusHTTP.METHOD_DELETE);
- POST Request
- Type of Mode : PARALLEL/SEQ
- Parallel Request
java client.setMode(OptimusHTTP.MODE_PARALLEL);
- Sequential Request
java client.setMode(OptimusHTTP.MODE_SEQ);
- Parallel Request
- Setup timeout values (optional, default is 10s)
- Connect Timeout
java client.setConnectTimeout(10 * 1000);
- Read Timeout
java client.setReadTimeout(10 * 1000);
- Connect Timeout
- Setup content type (optional, deafult is
CONTENT_TYPE_FORM_URL_ENCODED
)java client.setContentType(OptimusHTTP.CONTENT_TYPE_JSON);
Available Types
+ `OptimusHTTP.CONTENT_TYPE_FORM_URL_ENCODED` + `OptimusHTTP.CONTENT_TYPE_JSON` + `OptimusHTTP.CONTENT_TYPE_PDF` + `OptimusHTTP.CONTENT_TYPE_HTML` + `OptimusHTTP.CONTENT_TYPE_IMG_PNG` + `OptimusHTTP.CONTENT_TYPE_TEXT`
- Setup Headers (optional)
java ArrayMap<String, String> headerMap = new ArrayMap<>(); headerMap.put("Accept-Encoding", "gzip, deflate"); headerMap.put("Accept-Language", "en-US"); headerMap.put("Content-Language", "en-US"); client.setHeaderMap(headerMap);
- Type of Method : POST/GET
To make a request create an object of HttpReq class.
The client.makeRequest() function returns reference to each HttpReq object created which you can save in an ArrayList and then later on call cancel function on them to cancel the requests
ArrayList<HttpReq> refHttpReqList = new ArrayList<>(); try { // makeRequest() returns the reference of the request made // which can be used later to call the cancelReq() if required // if no request is made the makeRequest() returns null HttpReq req = client.makeRequest(SERVER, params, responseListener); if (req != null) refHttpReqList.add(req); } catch (Exception e) { e.printStackTrace(); }
To cancel one requests
client.cancelReq(req);
To cancel all requests
if (refHttpReqList.size() > 0) { for (int i = 0; i < refHttpReqList.size(); i++) client.cancelReq(refHttpReqList.get(i)); refHttpReqList.clear(); }
Implement the Callback
// Listener for the Response received from server private final OptimusHTTP.ResponseListener responseListener = new OptimusHTTP.ResponseListener() { @Override public void onSuccess(String msg) { System.out.println(msg); } @Override public void onFailure(String msg) { System.out.println(msg); } };
Screenshots
[sc1](img/sc1.png)
Pull Requests
I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:
- Match coding style (braces, spacing, etc.) This is best achieved using CMD+Option+L (Reformat code) on Mac (not sure for Windows) with Android Studio defaults. This project uses a modified version of Grandcentrix's code style, so please use the same when editing this project.
- If its a feature, bugfix, or anything please only change code to what you specify.
- Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
- Pull requests must be made against
develop
branch. Any other branch (unless specified by the maintainers) will get rejected. - Check for existing issues first, before filing an issue.
- Have fun!
License
Licensed under the Apache License, Version 2.0, click here for the full license.
Author & support
This project was created by Nishant Srivastava but hopefully developed and maintained by many others. See the the list of contributors here.
If you appreciate my work, consider buying me a cup of :coffee: to keep me recharged :metal:
- PayPal
- Bitcoin Address: 13PjuJcfVW2Ad81fawqwLtku4bZLv1AxCL
I love using my work and I'm available for contract work. Freelancing helps to maintain and keep my open source projects up to date!
*Note that all licence references and agreements mentioned in the OptimusHTTP README section above
are relevant to that project's source code only.