Inshorts News
NewsIntroducing the Inshorts-News-API
The Inshorts-News-API is a public API that allows you to access news articles from various sources. With this API, you can retrieve the latest news articles in a matter of seconds. This API is open source and is available on GitHub.
API Endpoint
The endpoint for this API is: https://inshortsapi.vercel.app/news
API Endpoints Parameters
category
: (optional) - Possible values are: "national", "business", "sports", "world", "politics", "technology", "startup", "entertainment", "miscellaneous", "hatke", "science", "automobile" (Default - top stories)
lang
: (optional) - Language of articles to be returned. Possible values are: "en" and "hi". (Default - English)
apikey
: (required) - An API key is needed to access this API. You can obtain a free API key by registering on the Inshorts API website.
Usage
To make use of the Inshorts-News-API, you need to send a GET request to the endpoint URL. Here's an example of how to retrieve the top stories in English:
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
axios.get('https://inshortsapi.vercel.app/news',{
headers: {
"Authorization": API_KEY
}
}).then((response) => {
console.log(response.data);
}).catch((error) => {
console.log(error);
});
To retrieve articles based on any other category, simply pass the category
parameter as shown below:
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
axios.get('https://inshortsapi.vercel.app/news?category=sports',{
headers: {
"Authorization": API_KEY
}
}).then((response) => {
console.log(response.data);
}).catch((error) => {
console.log(error);
});
Similarly, to retrieve articles in Hindi, pass the lang
parameter as shown below:
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
axios.get('https://inshortsapi.vercel.app/news?lang=hi',{
headers: {
"Authorization": API_KEY
}
}).then((response) => {
console.log(response.data);
}).catch((error) => {
console.log(error);
});
Conclusion
In conclusion, the Inshorts-News-API is a great tool to access news articles in a fast and efficient manner. With a free API key, you can access articles from different news sources and various categories. The example code provided in this blog should help you get started with using the API in JavaScript.