To use our Text Summarization API in Node.js, you need install the Unirest for Node.js client library first.
To utilize unirest for node.js, install the npm module:
npm install unirest
After installing the npm package, you can now start simplifying requests licke so:
var unirest = require('unirest')
Now you are probaly wondering how using Unirest to creat requests for the Text Summarization API in Note.js. 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 Node.js library like this:
var Request = unirest.post("https://textanalysis-text-summarization.p.mashape.com/text-summarizer")
.headers({
"X-Mashape-Authorization": "Your Mashape API Key",
"Content-Type": "application/json"
})
.send("{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\",\"text\":\"\",\"sentnum\":8}")
.end(function (response) {
console.log(response);
});
Here the Mashape API Key you can find in your Mashape account dashboard, copy it and replace it, and than excute it by the ruby interpreter, finally, you can get the response like this:
response.code # Status code
response.headers # Response headers
response.body # Parsed body
response.raw_body # Unparsed body
Now it's time to enjoy our Text Summarization API for your Node.js 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: