qdb-api-plus
A better API wrapper for Quote Database. Fork of qdb-api.
Looking for a REST API? See qdb-rest-api
npm install qdb-api-plus
const qdb = require('qdb-api-plus')
qdb-api vs qdb-api-plus
- qdb-api-plus doesn't use
axios
- qdb-api-plus has slightly better documentation
- qdb-api-plus has a couple more methods like
latestID
and randomID
- You can search for any number of results under 101 with qdb-api-plus, instead of being constrained to 10, 25, 50, 75, or 100
- You can get any amount of latest/random quotes under 51 with qdb-api-plus, instead of just getting one
Methods available
- Get a random quote or a random ID
- Get the latest quote or it's ID
- Get specific quote by it's id
- Search for a quote
Get a random quote
Parameters
count
(optional) - How many quotes to get
Returns a quote if count
is 1, and an array of quotes otherwise
Example:
qdb.random()
.then(quote => {
console.log(quote.id);
console.log(quote.score);
console.log(quote.text);
})
.catch(reason => {
console.log(reason);
});
Get a random quote ID
Example:
qdb.randomID()
.then(id => {
console.log(id);
})
.catch(reason => {
console.log(reason);
});
Get the latest quote
Parameters
count
(optional) - How many quotes to get
Returns a quote if count
is 1, and an array of quotes otherwise
Example:
qdb.latest()
.then(quote => {
console.log(quote.id);
console.log(quote.score);
console.log(quote.text);
})
.catch(reason => {
console.log(reason);
});
Get the latest quote ID
Example:
qdb.latestID()
.then(id => {
console.log(id);
})
.catch(reason => {
console.log(reason);
});
Get a specific quote by its ID
Parameters
Example:
qdb.get(4680)
.then(quote => {
console.log(quote.id);
console.log(quote.score);
console.log(quote.text);
})
.catch(reason => {
console.log(reason);
});
Search for a quote
Parameters
Search string
Sort by
- 0
for score, 1
for numberNumber of results
- Any number under 101
Returns a quote if Number of results
is 1, and an array of quotes otherwise
Example:
qdb.search('tom', 0, 10)
.then(quotes => {
quotes.forEach(quote => {
console.log(quote.id);
console.log(quote.score);
console.log(quote.text);
});
})
.catch(reason => {
console.log(reason);
});
How it works
First, the program gets a specific bash.org website:
`http://bash.org/?${id}`
'http://bash.org/?latest'
'http://bash.org/?random'
`http://bash.org/?search=${query}&sort=${sort}&show=${count}`
Then, it uses cheerio
to scrape the page for the quote text, the votes, and the ID.
Disclaimer
Please note that is an unofficial API.