AfpNews API
This project is aimed to help javascript developers use the AFP Core API.
It provides authentication, searching for documents function, and online news product.
Getting Started
This package is available both for NodeJS and browsers. That's why two versions are available on the ./dist
directory.
Prerequisites
You'll need an API key and credentials to retrieve all content from the API.
Installing
Node
npm install --save afpnews-api
const AfpNews = require('afpnews-api')
import AfpNews from 'afpnews-api'
Browser
<script src="./dist/afpnews-api.umd.js"></script>
Let's start using it
const afpNews = new AfpNews({ clientId, clientSecret })
await afpNews.authenticate({ username, password })
afpNews.on('tokenChanged', token => console.log(token))
const { documents } = await afpNews.search()
for await (const doc of afpNews.searchAll()) {
console.log(doc)
}
const document = await afpNews.get(uno)
const { documents } = await afpNews.mlt(uno)
const { keywords } = await afpNews.list('slug')
Query parser
The above request use default parameters stored in ./src/default-search-params.js
You can pass your own parameters to the search function, that will overide the defaults.
The query parameter can be used to look precisely for a field (title:Macron
) and may include logical parameters (Macron OR Merkel
, Macron AND NOT Merkel
, (title:Macron OR title:Merkel) AND country:fra
).
Development
Clone the repository, then npm install
Build and minify your work for browsers and node with npm run build
Running the tests
Just npm test
to execute all tests in ./tests
You will need some environment variables in a .env file :
AFPNEWS_BASE_URL=
AFPNEWS_API_KEY=
AFPNEWS_CLIENT_ID=
AFPNEWS_CLIENT_SECRET=
AFPNEWS_USERNAME=
AFPNEWS_PASSWORD=
Built With
Authors
License
This project is licensed under the MIT License - see the LICENSE.md file for details