Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@trivia-api/fetch

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trivia-api/fetch

Functions to fetch data from The Trivia API.

  • 1.38.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

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 });
});

Keywords

FAQs

Package last updated on 04 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc