Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

newsapi-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

newsapi-wrapper

A wrapper around the News API (https://newsapi.org/) that exposes a Promise-like interface

  • 1.0.2
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

newsapi-wrapper

newsapi-wrapper is a convenient wrapper to call the News API. All you will need is an API key that you can get here.

Usage

const newsapi = require('newsapi-wrapper');
newsapi.request()
   .setCountry('ca')
   .setCategory('sports')
   .setPageSize(25)
   .send()
   .then(response => {
       console.log(`Results: ${response.totalResults}`);
       response.articles.forEach(article => {
           console.log(article.title);
       });
   })
   .catch(err => {
       console.log(err);
   });

Installation

NPM

npm install newsapi-wrapper

yarn

yarn add newsapi-wrapper

API

setDefault

Sets a single default value. Possible keys: country, category, apiKey, pageSize

newsapi.setDefault('country', 'de');

setDefaults

Sets multiple default values at once. Takes an object as a parameter. Possible keys: country, category, apiKey, pageSize.

newsapi.setDefaults({
    country: 'de',
    pageSize: 10,
    category: 'sports'
});

getCategories

Returns an array containing all valid categories, which are: business, entertainment, general, health, science, sports, technology

request

Returns an object you can use to build a request, send it, and process the result. Intended to used as a chain of method calls:

newsapi.request()
       .setCategory('health')
       .setPageSize(15)
       .send();

The call to send returns a promise which resolves when the response from the News API is received as intended. Otherwise, it is rejected:

newsapi.request()
       .setCategory('health')
       .setPageSize(15)
       .send()
       .then(response => {
           // Probably do something with response.articles
       })
       .catch(err => {
           console.log(err);
       });

Keywords

FAQs

Package last updated on 28 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc