Socket
Socket
Sign inDemoInstall

ng-news-api

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ng-news-api

An Angular 2 library for NewsAPI.


Version published
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

newsapi

An Angular 2 library for NewsAPI.

Up-to-date news headlines and metadata in JSON from 70+ popular news sites. Powered by NewsAPI.org.

You will need an API key from NewsApi.

Please look at their documentation to see how to use the API. The convenience functions provided by this module simply pass their options along as querystring parameters to the REST API, so the documentation is totally valid.

Developed By Ajani Eniola Solomon

##Install

npm i ng-news-api --save

##Add to your project

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { NewsApiModule } from 'news-api';
import { NewsApiService } from 'news-api';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NewsApiModule.forRoot({apiKey: 'XXXXXXXXX'})
  ],
  providers: [NewsApiService],
  bootstrap: [AppComponent]
})
export class AppModule { }


Note apiKey can only be gotten from NewsApi.

##USAGE

import { Component } from '@angular/core';
import { NewsApiService } from 'news-api';

@Component({
  selector: 'ld-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
 data;
  country = 'ng';
  constructor(private service: NewsApiService) {
   this.service.getNewsByHeadlines(this.country).subscribe(res => {
  this.data = JSON.parse(res);
  console.log(this.data);
   });
  }
}

##More

###getNewsByHeadlines

Request parameters:

  • country eg'us',
  • category eg 'business'
  • pageSize eg 30

###getEveryThing

Request parameters:

  • q eg 'bitcoin'
  • language eg 'en'
  • pageSize eg 30
  • sortBy eg'relevancy'

###getSource

Request parameters:

  • category eg 'sports'
  • language eg 'en'
  • pageSize eg 30
  • sortBy eg 'relevancy'

##Response object

1 status

2 totalResults

3 articles

4 source

5 author

6 title

7 description

8 url

9 urlToImage

10 publishedAt

Keywords

FAQs

Last updated on 18 Jun 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc