This API allows users to retrieve random facts from a list of pre-defined facts. There are several endpoints available for accessing different types of facts.
This API uses the following dependencies:
express
for creating the API serverexpress-rate-limit
for rate limiting the APInode-schedule
for scheduling taskscors
for allowing cross-origin requests
The following endpoints are available for retrieving facts:
GET /fact
returns a random fact from the listGET /fact/reqs
returns the number of requests made to the APIGET /fact/specify/:number
returns the fact at the specified index in the listGET /fact/specify/count/:number
returns the specified number of facts, starting from the beginning of the listGET /fact/specify/count/random/:number
returns the specified number of random factsGET /fact/hourly
returns a random fact, selected every hourGET /fact/app
returns a random fact for use in an appGET /fact/hourly/app
returns a random fact for use in an app, selected every hour
To set up the development environment, follow these steps:
- Clone the repository to your local machine
- Run
npm install
to install the dependencies - Start the API server by running
node index.js
- The API will be running at
http://localhost:3000
- The
/fact/app
and/fact/hourly/app
endpoints log the time that the fact was accessed in the console - The
/fact/hourly
and/fact/hourly/app
endpoints use a scheduling function to select a new fact at midnight every day - The API is rate limited to 100 requests per 15 minutes for all endpoints