To use our Text Summarization API in Java, you need install the Unirest for Java client library.
It's about as easy as doing these little steps:
You can use Maven by including the library:
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.3.11</version>
</dependency>
There are dependencies for Unirest-Java, these should be already installed, and they are as follows:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
If you don't use Maven, you can direcly include JAR file in the classpath: http://oss.sonatype.org/content/repositories/releases/com/mashape/unirest/unirest-java/1.3.11/unirest-java-1.3.11.jar
Don't forget to install the dependencies(org.json, httpclient 4.3.3, httpmime4.3.3, httpasyncclient 4.0.1) in the classpath too
Now you are probaly wondering how using Unirest to creat requests for the Text Summarization API in Java. Let's start with the previous json rquest body example:
{
"url": "http://en.wikipedia.org/wiki/Automatic_summarization",
"text": "",
"sentnum": 8
}
The request created with Unirest Java library like this:
HttpResponse request = Unirest.post("https://textanalysis-text-summarization.p.mashape.com/text-summarizer")
.header("X-Mashape-Authorization", "Your Mashape API Key")
.header("Content-Type", "application/json")
.body("{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\",\"text\":\"\",\"sentnum\":8}")
.asJson();
Here the Mashape API Key you can find in your Mashape account dashboard, copy it and replace it, now it's time to enjoy our Text Summarization API for your Java Projects.
Unirest is a set of lightweight HTTP libraries available in multiple languages, ideal for most applications:
- Make GET, POST, PUT, PATCH, DELETE requests
- Both syncronous and asynchronous (non-blocking) requests
- It supports form parameters, file uploads and custom body entities
- Supports gzip
- Supports Basic Authentication natively
- Customizable timeout
- Customizable default headers for every request (DRY)
- Automatic JSON parsing into a native object for JSON responses
For other languages support by Text Summarization API, you can find the document link below: