ng-news-api
v0.0.7
Published
An Angular 2 library for NewsAPI.
Downloads
7
Readme
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