tdb-api

1.5.5 • Public • Published

TDB-API

About

A wrapper for OpenTDB API made in Javascript

Created By: ItsHisoka17, SkellyM386

Simply Usage

const TDB_API = require('tdb-api');

const trivia = new TDB_API();

trivia.getQuestions({amount: 10, category: 'Sports', difficulty: 'medium'})
.then(res => {
    console.log(res)
});

Handling Sessions

const TDB_API = require('tdb-api');

const trivia = new TDB_API();


async function start(){
    let token = await trivia.create_session_token(); //Creates a token
    trivia.getQuestions({amount: 10, category: 'Sports', difficulty: 'medium', token: token})
    .then(res => {
        console.log(res) //Returns: {category: string, type: string, difficulty: string, question: string, correct_answer: string, incorrect_answers: Array<string>}
    })
    .catch(async () => {
        let newToken = await trivia.refresh_token(token); //Requests a new token and invalidates the previous one
        trivia.getQuestions({amount: 10, category: 'Sports', difficulty: 'medium', token: newToken})
        .then(res => {
            console.log(res)
        })
    })

}
start()

Categories:

  • General Knowledge

  • Books

  • Films

  • Music

  • Musical & Theatre

  • TV

  • Video Games

  • Board Games

  • Science & Nature

  • Computers

  • Mathematics

  • Mythology

  • Sports

  • Geography

  • History

  • Politics

  • Art

  • Celebrities

  • Animals

  • Vehicles

  • Comics

  • Gadgets

  • Anime & Manga

  • Cartoons & Animations

Contact

Discord | Github

Readme

Keywords

Package Sidebar

Install

npm i tdb-api

Weekly Downloads

0

Version

1.5.5

License

ISC

Unpacked Size

9.32 kB

Total Files

8

Last publish

Collaborators

  • itshisoka17