1.38.0 • Published 1 year ago
@trivia-api/fetch v1.38.0
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) => {
// questions is an array of questions
});
searchQuestions
import { searchQuestions } from "@trivia-api/fetch";
searchQuestions({ freetext: "france" }).then((questions) => {
// questions is an array of questions that have either the tag 'france'
// or match 'france' to a freetext search on the question.
});
getMetadata
import { getMetadata } from "@trivia-api/fetch";
getMetadata().then((metadata) => {
// metadata is an object representing the number of questions in the API, broken down by category and state
});
getTags
import { getTags } from "@trivia-api/fetch";
getTags().then((tags) => {
// tags is an array of all the tags used by questions in the API
});
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);
// If the promise resolves then the question has been successfully updated
} catch {
// If the promise is rejected then the question has not been updated. Did you
// pass in a valid API key? Is the ID wrong? Did you miss a required property?
}
createSession
import { createSession, getQuestions } from "@trivia-api/fetch";
createSession().then((session) => {
// You can use the session object to request questions with no duplicates
// Request 10 questions from the session you just created
getQuestions({ session: session.id, limit: 10 });
/**
* Request 10 more questions from the session you just created. These
* questions are guaranteed to be different to the questions previously
* received.
*/
getQuestions({ session: session.id, limit: 10 });
});
1.38.0
1 year ago
1.37.0
2 years ago
1.35.0
2 years ago
1.31.0
2 years ago
1.22.0
2 years ago
1.23.0
2 years ago
1.24.0
2 years ago
1.16.0
3 years ago
1.15.0
3 years ago
1.14.0
3 years ago
1.13.0
3 years ago
1.12.0
3 years ago
1.8.0
3 years ago
1.11.0
3 years ago
1.10.0
3 years ago
1.2.0
3 years ago
1.0.19
3 years ago
1.1.0
3 years ago
1.0.18
3 years ago
1.0.17
3 years ago
1.7.0
3 years ago
1.6.1
3 years ago
1.6.0
3 years ago
1.5.1
3 years ago
1.4.0
3 years ago
1.3.0
3 years ago
1.0.16
3 years ago
1.0.15
3 years ago
1.0.14
3 years ago
1.0.13
3 years ago
1.0.12
3 years ago
1.0.11
3 years ago
1.0.10
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago