Skip to content

Random Fact API

This documentation page covers the Random Fact API in the TeamTBM ecosystem style. The endpoint returns a JSON response containing a random fact and a credit string that can be displayed on your website.

Response Format

All successful responses are returned in JSON format.

{
    "credit": "API Data from <a href='https://dev.tylermwise.uk/v1/randomfact'>tylermwise.com</a>",
    "fact": "A random fact will appear here!"
}

Response Fields:

  • credit (string) - Attribution text for the API source, returned as HTML.
  • fact (string) - A random fact string.

Authentication Methods

This endpoint is publicly accessible and does not require authentication.

Characteristics:

  • No authentication required
  • JSON response format
  • Suitable for websites and lightweight integrations
  • Includes optional credit output

Usage:

curl "https://api.tylermwise.uk/v1/randomfact"

You can fetch and decode the API response in PHP using file_get_contents() and json_decode().

Example:

<?php
    $contents = file_get_contents("https://api.tylermwise.uk/v1/randomfact");
    $data = json_decode($contents);
?>

Endpoint

GET /v1/randomfact

Example Request

curl "https://api.tylermwise.uk/v1/randomfact"

Example Response

{
    "credit": "API Data from <a href='https://dev.tylermwise.uk/v1/randomfact'>tylermwise.com</a>",
    "fact": "A random fact will appear here!"
}

Response Fields

Field Type Description
credit string Attribution text for the API source.
fact string The random fact returned by the endpoint.

PHP Usage

Fetch API Data

<?php
    $contents = file_get_contents("https://api.tylermwise.uk/v1/randomfact");
    $data = json_decode($contents);
?>

Output the Random Fact

<?php echo $data->fact; ?>

Output the API Credit

<?php echo $data->credit; ?>

Notes

  • The endpoint returns a random fact and a credit value in the same response.
  • The credit field is intended for optional attribution on your website.
  • The original source recommends adding the credit line to support the API.

HTTP Status Codes

Standard responses may include:

  • 200 - Success.
  • 400 - Bad Request.
  • 429 - Too Many Requests.
  • 500 - Internal Server Error.

Versioning

This page documents version 1 of the Random Fact API, available under the /v1/ path.