news-wrapper
[WIP] A Javascript wrapper to work with News API.
Installation
$ npm install --save news-wrapper
How to use
ES6
// to import a specific method; const news = token: 'YOUR_TOKEN_HERE'; // using methodconst promise = newssearch;promise;
CommonJS
const NewsWrapper = default; const news = token: 'YOUR_TOKEN_HERE';
UMD in Browser
<!-- to import non-minified version --> <!-- to import minified version -->
After that the library will be available to the Global as NewsWrapper
. Follow an example:
const news = token: 'YOUR_TOKEN_HERE'; const sources = newssearch;
Methods
Follow the methods that the library provides.
search.topheadlines(query)
This method provides live top and breaking headlines for a single source, or multiple sources. Test in npm runkit.
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
sources |
string | 'Any source query' |
category |
string | 'Any category query' |
language |
string | 'Any language' |
country |
string | 'Any country' |
The argument query
is optional. In case nothing is passed, the method will retrieve Techcrunch available headlines. In case more than one source is needed, you can add a string separated by commas, like 'cnn,techcrunch,bbc' for example.
Default: Techcrunch.
For more details about country
and language
supported, please check NewsAPI
Example
newssearch;
If you want to specify more than one source:
newssearch;
search.sources(query)
This method will get all sources available. It's possible to filter by either
category
and/orcountry
. Test in npm runkit.
Arguments
Argument | Type | Options |
---|---|---|
category |
string | 'Any of the below list' |
country |
string | 'Any of the below list' |
language |
string | 'Any of the below list' |
-
Available categories:
business
entertainment
gaming
general
health-and-medical
music
politics
science-and-nature
sport
technology
Default: all categories. -
Available countries:
ar
au
br
ca
cn
de
es
fr
gb
hk
ie
in
is
it
nl
no
pk
ru
sa
sv
us
za
Default: all countries. -
Available languages:
ar
en
cn
de
es
fr
he
it
nl
no
pt
ru
sv
ud
Default: all languages.
Example
newssearch
search.everything(query)
This method retrieves all news related to the query passed in. It includes all kind of sources. Test in npm runkit.
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
sources |
string | 'Any source query' |
from |
string | 'Starting date' |
to |
string | 'Ending date' |
page |
int | 'Pagination number' |
The only required parameter is query, all other parameters are optional. Both from
and to
needs to be in ISO 8601 format
(e.g. 2018-01-02
or 2018-01-02T12:16:22
)
- Default page:
1
Example
newssearch
newssearch
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
License
This project is licensed under the ISC License - see the LICENSE.md file for details