|
1 | 1 | # currentsapi |
2 | 2 |
|
3 | | -A node interface for CurrentsAPI. |
| 3 | +The official Node.js SDK for the [Currents API](https://currentsapi.services/en/docs/). |
4 | 4 |
|
5 | | -Latest news headlines and metadata in JSON from 13,000 popular news sites. Powered by Currents Api |
| 5 | +## Installation |
6 | 6 |
|
7 | | -In order to use this package you need to register at [https://currentsapi.services/en/register](https://currentsapi.services/en/register) |
| 7 | +```bash |
| 8 | +npm install currentsapi |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
8 | 12 |
|
9 | | -Please refer to our [documentation](https://currentsapi.services/en/documents) to see details about how to use the API. The convenience functions provided by this module is simply passing your options along as querystring parameters to the REST API, so the [documentation](https://currentsapi.services/en/documents) is totally valid. |
| 13 | +```js |
| 14 | +const CurrentsAPI = require('currentsapi'); |
| 15 | +const api = new CurrentsAPI('YOUR_API_KEY'); |
| 16 | +``` |
10 | 17 |
|
11 | | -There are some usage examples below to see how these options should be passed in. |
| 18 | +## Endpoints |
12 | 19 |
|
13 | | -If you use this in a project, kindly add an attribution : 'powered by Currents API' with links back to Currents Api. |
| 20 | +### Latest News |
14 | 21 |
|
15 | | -## Add to your project |
16 | | -```shell |
17 | | -$ npm i -s currentsapi |
| 22 | +```js |
| 23 | +api.latestNews({ language: 'en' }) |
| 24 | + .then(response => console.log(response)); |
18 | 25 | ``` |
19 | 26 |
|
20 | | -## Test |
21 | | -```shell |
22 | | -$ API_KEY=<your api key> npm test |
| 27 | +### Search |
| 28 | + |
| 29 | +```js |
| 30 | +api.search({ keywords: 'OpenAI', language: 'en' }) |
| 31 | + .then(response => console.log(response)); |
23 | 32 | ``` |
24 | 33 |
|
25 | | -## Example usage of API |
26 | | -All methods support promises and node-style callbacks. |
| 34 | +Supported parameters: |
| 35 | + |
| 36 | +- `keywords` |
| 37 | +- `language` |
| 38 | +- `country` |
| 39 | +- `category` |
| 40 | +- `start_date` |
| 41 | +- `end_date` |
| 42 | + |
| 43 | +### Available Resources |
| 44 | + |
27 | 45 | ```js |
28 | | -const CurrentsAPI = require('currentsapi'); |
29 | | -const currentsapi = new CurrentsAPI('YOUR_API_KEY'); |
30 | | - |
31 | | -// To query latest news |
32 | | -// All options passed to search are optional |
33 | | -currentsapi.search({ |
34 | | - keywords: 'Trump', |
35 | | - language: 'en', |
36 | | - country: 'US' |
37 | | -}).then(response => { |
38 | | - console.log(response); |
39 | | - /* |
40 | | - { |
41 | | - status: "ok", |
42 | | - news: [...] |
43 | | - } |
44 | | - */ |
45 | | -}); |
46 | | - |
47 | | - |
48 | | -If you like this package you can follow us at [Twitter](https://twitter.com/currentsapi) |
| 46 | +api.availableLanguages(); |
| 47 | +api.availableRegions(); |
| 48 | +api.availableCategory(); |
| 49 | +``` |
| 50 | + |
| 51 | +## Authentication |
| 52 | + |
| 53 | +All requests are authenticated using an `Authorization` header. Pass your API key when instantiating the client: |
| 54 | + |
| 55 | +```js |
| 56 | +const api = new CurrentsAPI('YOUR_API_KEY'); |
| 57 | +``` |
| 58 | + |
| 59 | +Get your API key at [https://currentsapi.services/en/register](https://currentsapi.services/en/register). |
| 60 | + |
| 61 | +## License |
| 62 | + |
| 63 | +MIT |
0 commit comments