npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

riddle-api-client

v1.1.0

Published

An API to fetch multiple riddles from the Riddles API

Downloads

124

Readme

Riddles API Client

This is a Node.js API client to fetch multiple riddles from the [Riddles API].

Usage

You can specify the number of riddles you want to retrieve by passing a count parameter in the query string.

Example:

GET http://localhost:3000/riddles?count=5

Response:

[
  {
    "riddle": "A phone rings 9 times, and no one answers it. A horse eats 9 pounds of grain. A bannana grows 9 inches every day. and the computer gets 9 mail messages every day.  What is always in the above paragraph?",
    "answer": "Letters and words"
  },
  {
    "riddle": "What can you catch but not throw?",
    "answer": "A cold"
  },
  {
    "riddle": "What falls but doesn't break, and what breaks but doesn't fall?",
    "answer": "Night and Day"
  },
  {
    "riddle": "A boy was at a carnival and went to a booth where a man said to the boy, “If I write your exact weight on this piece of paper then you have to give me $50, but if I cannot, I will pay you $50.” The boy looked around and saw no scale so he agrees, thinking no matter what the carny writes he'll just say he weighs more or less. In the end the boy ended up paying the man $50. How did the man win the bet?",
    "answer": "The man did exactly as he said he would and wrote “your exact weight”on the paper"
  },
  {
    "riddle": "What word can be written forward, backward or upside down, and can still be read from left to right?",
    "answer": "NOON"
  }
]

Endpoints

  1. GET /riddles?count=[count]
    • Fetches the specified number of riddles.
  2. POST /check-answer
    • Compares the user's answer with the correct answer for a specific riddle.

Example Usage:

  • Check answer:
    POST http://localhost:3000/check-answer
    Content-Type: application/json
    {
      "riddle": {
        "riddle": "A boy was at a carnival...",
        "answer": "The man did exactly as he said he would..."
      },
      "userAnswer": "He wrote your exact weight"
    }

Example response:


{
  "message": "Correct answer!"
}

Or, if the answer is incorrect:

{
  "message": "Incorrect answer. Try again!"
}

Testing the Answer Check:

Once the server is running, you can test the check-answer API by sending a POST request to the /check-answer endpoint with a riddle object and the user's answer in the request body. The server will compare the normalized answers and respond with either a confirmation of correctness or a prompt to try again.

You can use tools like Postman or Insomnia, or write a frontend to send requests to the backend.