Trivia API Fetch Client
Functions to fetch data from The Trivia API.
Installation
Install with npm install @trivia-api/fetch
.
Usage
Functions
getQuestions
import { getQuestions } from "@trivia-api/fetch";
getQuestions({ limit: 5 }).then((questions) => {
});
searchQuestions
import { searchQuestions } from "@trivia-api/fetch";
searchQuestions({ freetext: "france" }).then((questions) => {
});
getMetadata
import { getMetadata } from "@trivia-api/fetch";
getMetadata().then((metadata) => {
});
getTags
import { getTags } from "@trivia-api/fetch";
getTags().then((tags) => {
});
updateQuestion
import { updateQuestion } from "@trivia-api/fetch";
const question = await getQuestions()[0];
const newQuestion = {
...question,
correctAnswer: "A different answer",
};
const API_KEY = "abcd1234";
try {
await updateQuestion(API_KEY, newQuestion);
} catch {
}
createSession
import { createSession, getQuestions } from "@trivia-api/fetch";
createSession().then((session) => {
getQuestions({ session: session.id, limit: 10 });
getQuestions({ session: session.id, limit: 10 });
});