http-request alternatives and similar packages
Based on the "Network" category.
Alternatively, view http-request alternatives based on common mentions on social networks and blogs.
-
okhttp
Square’s meticulous HTTP client for the JVM, Android, and GraalVM. -
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. -
async-http-client
Asynchronous Http and WebSocket Client library for Java -
AndroidNetworking
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀 -
Android Volley
Official Android HTTP library that makes networking for easier and faster. -
robospice
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. -
unirest-java
Unirest in Java: Simplified, lightweight HTTP client library. -
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. -
node-android
Run Node.js on Android by rewrite Node.js in Java -
No Internet Layout Library
#layout #check_internet -
OptimusHTTP
:satellite: [Android Library] Simplified async networking in android -
Rx.Network
Observe Android's CONNECTIVITY_CHANGE broadcasts using RxJava. -
networking
An android asynchronous http client built on top of HttpURLConnection. -
NetworkConnection
No description, website, or topics provided. -
Minimized API Service Library
Minimized API library which is used call the server request in andorid. -
Packetzoom
SDK for optimizing HTTP requests and free analytics service for networking.
Appwrite - The open-source backend cloud platform
* 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 http-request or a related project?
README
Http Request 
A simple convenience library for using a HttpURLConnection to make requests and access the response.
This library is available under the MIT License.
Usage
The http-request library is available from Maven Central.
<dependency>
<groupId>com.github.kevinsawicki</groupId>
<artifactId>http-request</artifactId>
<version>6.0</version>
</dependency>
Not using Maven? Simply copy the HttpRequest class into your project, update the package declaration, and you are good to go.
Javadocs are available here.
FAQ
Who uses this?
See here for a list of known projects using this library.
Why was this written?
This library was written to make HTTP requests simple and easy when using a HttpURLConnection
.
Libraries like Apache HttpComponents are great but sometimes
for either simplicity, or perhaps for the environment you are deploying to (Android),
you just want to use a good old-fashioned HttpURLConnection
. This library seeks
to add convenience and common patterns to the act of making HTTP requests such as
a fluid-interface for building requests and support for features such as multipart
requests.
Bottom line: The single goal of this library is to improve the usability of the
HttpURLConnection
class.
What are the dependencies?
None. The goal of this library is to be a single class class with some inner static classes. The test project does require Jetty in order to test requests against an actual HTTP server implementation.
How are exceptions managed?
The HttpRequest
class does not throw any checked exceptions, instead all low-level
exceptions are wrapped up in a HttpRequestException
which extends RuntimeException
.
You can access the underlying exception by catching HttpRequestException
and calling
getCause()
which will always return the original IOException
.
Are requests asynchronous?
No. The underlying HttpUrlConnection
object that each HttpRequest
object wraps has a synchronous API and therefore all methods on HttpRequest
are also synchronous.
Therefore it is important to not use an HttpRequest
object on the main thread
of your application.
Here is a simple Android example of using it from an AsyncTask:
private class DownloadTask extends AsyncTask<String, Long, File> {
protected File doInBackground(String... urls) {
try {
HttpRequest request = HttpRequest.get(urls[0]);
File file = null;
if (request.ok()) {
file = File.createTempFile("download", ".tmp");
request.receive(file);
publishProgress(file.length());
}
return file;
} catch (HttpRequestException exception) {
return null;
}
}
protected void onProgressUpdate(Long... progress) {
Log.d("MyApp", "Downloaded bytes: " + progress[0]);
}
protected void onPostExecute(File file) {
if (file != null)
Log.d("MyApp", "Downloaded file to: " + file.getAbsolutePath());
else
Log.d("MyApp", "Download failed");
}
}
new DownloadTask().execute("http://google.com");
Examples
Perform a GET request and get the status of the response
int response = HttpRequest.get("http://google.com").code();
Perform a GET request and get the body of the response
String response = HttpRequest.get("http://google.com").body();
System.out.println("Response was: " + response);
Print the response of a GET request to standard out
HttpRequest.get("http://google.com").receive(System.out);
Adding query parameters
HttpRequest request = HttpRequest.get("http://google.com", true, 'q', "baseball gloves", "size", 100);
System.out.println(request.toString()); // GET http://google.com?q=baseball%20gloves&size=100
Using arrays as query parameters
int[] ids = new int[] { 22, 23 };
HttpRequest request = HttpRequest.get("http://google.com", true, "id", ids);
System.out.println(request.toString()); // GET http://google.com?id[]=22&id[]=23
Working with request/response headers
String contentType = HttpRequest.get("http://google.com")
.accept("application/json") //Sets request header
.contentType(); //Gets response header
System.out.println("Response content type was " + contentType);
Perform a POST request with some data and get the status of the response
int response = HttpRequest.post("http://google.com").send("name=kevin").code();
Authenticate using Basic authentication
int response = HttpRequest.get("http://google.com").basic("username", "p4ssw0rd").code();
Perform a multipart POST request
HttpRequest request = HttpRequest.post("http://google.com");
request.part("status[body]", "Making a multipart request");
request.part("status[image]", new File("/home/kevin/Pictures/ide.png"));
if (request.ok())
System.out.println("Status was updated");
Perform a POST request with form data
Map<String, String> data = new HashMap<String, String>();
data.put("user", "A User");
data.put("state", "CA");
if (HttpRequest.post("http://google.com").form(data).created())
System.out.println("User was created");
Copy body of response to a file
File output = new File("/output/request.out");
HttpRequest.get("http://google.com").receive(output);
Post contents of a file
File input = new File("/input/data.txt");
int response = HttpRequest.post("http://google.com").send(input).code();
Using entity tags for caching
File latest = new File("/data/cache.json");
HttpRequest request = HttpRequest.get("http://google.com");
//Copy response to file
request.receive(latest);
//Store eTag of response
String eTag = request.eTag();
//Later on check if changes exist
boolean unchanged = HttpRequest.get("http://google.com")
.ifNoneMatch(eTag)
.notModified();
Using gzip compression
HttpRequest request = HttpRequest.get("http://google.com");
//Tell server to gzip response and automatically uncompress
request.acceptGzipEncoding().uncompress(true);
String uncompressed = request.body();
System.out.println("Uncompressed response is: " + uncompressed);
Ignoring security when using HTTPS
HttpRequest request = HttpRequest.get("https://google.com");
//Accept all certificates
request.trustAllCerts();
//Accept all hostnames
request.trustAllHosts();
Configuring an HTTP proxy
HttpRequest request = HttpRequest.get("https://google.com");
//Configure proxy
request.useProxy("localhost", 8080);
//Optional proxy basic authentication
request.proxyBasic("username", "p4ssw0rd");
Following redirects
int code = HttpRequest.get("http://google.com").followRedirects(true).code();
Custom connection factory
Looking to use this library with OkHttp? Read here.
HttpRequest.setConnectionFactory(new ConnectionFactory() {
public HttpURLConnection create(URL url) throws IOException {
if (!"https".equals(url.getProtocol()))
throw new IOException("Only secure requests are allowed");
return (HttpURLConnection) url.openConnection();
}
public HttpURLConnection create(URL url, Proxy proxy) throws IOException {
if (!"https".equals(url.getProtocol()))
throw new IOException("Only secure requests are allowed");
return (HttpURLConnection) url.openConnection(proxy);
}
});
Contributors
- Kevin Sawicki :: contributions
- Eddie Ringle :: contributions
- Sean Jensen-Grey :: contributions
- Levi Notik :: contributions
- Michael Wang :: contributions
- Julien HENRY :: contributions
- Benoit Lubek :: contributions
- Jake Wharton :: contributions
- Oskar Hagberg :: contributions
- David Pate :: contributions
- Anton Rieder :: contributions
- Jean-Baptiste Lièvremont :: contributions
- Roman Petrenko :: contributions
*Note that all licence references and agreements mentioned in the http-request README section above
are relevant to that project's source code only.