Fortune Cookie API Documentation

Step into a world of delightful surprises with the Fortune Cookie API—an enchanting collection of timeless sayings that adds a touch of whimsy to your dining experience. Much like the joyous ritual of cracking open a fortune cookie at the end of a meal, our API brings you a curated assortment of charming messages sourced from various corners of the web.

Contents

  1. Object Properties & Structure
  2. Operating Modes
    1. Stats Mode
    2. Random Mode
    3. Batch Mode
    4. Fortune Cookie of the Day
  3. Use Limits

1. Object Properties

A fortune cookie object has the following properties.

PropertyDescription
textThe fortune text.
sourceThe source domain text.
urlThe source hyperlink.
numbersLucky numbers.
htmlThe fortune in pre-formatted HTML.

Example Response {object}

{
"text": "The fortune cookie text will be displayed here.",
"source": "www.example.com",
"url": "https://www.example.com/some-page/",
"numbers": "76, 36, 85, 82, 51, 5",
"html": "<blockquote>Pre-formatted HTML<footer>Source</footer></blockquote>"
}

2. Operating Modes

There are several API modes depending on the type of data you want to retrieve.

i. Stats Mode

https://api.viewbits.com/v1/fortunecookie?mode=stats

Use this call to return information like current version and the number of fortune cookies in the database.

Response:

{"info":"Fortune Cookies v1.0","entries":162}

ii. Random Mode

https://api.viewbits.com/v1/fortunecookie?mode=random

Use this call to return a single random fortune cookie object.

Response:

{object}

iii. Batch Mode

https://api.viewbits.com/v1/fortunecookie?mode=batch

When operating in batch mode, the API will return an array of random objects. This is mainly used when you want to cache data locally within your app. This is the most efficient method to work with several objects within your app.

The default limit is 50 items. When no API key is provided, the batch is limited to 10 entries.

Response:

[ {object},{object},...{object} ]

iv. Fortune Cookie of The Day

https://api.viewbits.com/v1/fortunecookie?mode=today

Each day we feature a single fortune cookie from our database, which you can call using the [today] mode. To reduce server load, this response should be loaded into your app cache and refreshed daily rather than making a call each time you want to display an object in your project. A new fortune is generated at midnight server time (00:00 CST).

Response:

{object}

3. Use Limits

When no API key is provided, calls are limited to 5 per 30 second period. Its recommended that you use batch mode to cache the data in a local file, then updating only as needed. To increase rate limits and disable CORS, you must provide an API key by adding &key=[YOUR_KEY] to the end of your call.

Example:

https://api.viewbits.com/v1/fortunecookie?mode=random&key=[YOUR_KEY]