Advice Slip API

Entertainment
Beginner

Overview

Free API for random advice slips

Integration Guide

Step 1: Understanding the API

The Advice Slip API is a free, public API that doesn't require authentication. It provides random advice slips, specific advice by ID, and search functionality.

Step 2: Set Up Your Project

Create the necessary files for your advice application:

  • index.html - The HTML structure
  • styles.css - CSS for styling
  • script.js - JavaScript for API integration

Step 3: Implement the Code

Copy the following code into your project files:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Daily Advice</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div class="container">
    <h1>Daily Advice</h1>
    
    <div class="advice-container">
      <div class="advice-card">
        <p id="advice-text">Click the button to get some advice...</p>
        <span id="advice-id"></span>
      </div>
      
      <button id="get-advice-btn">Get Advice</button>
    </div>
    
    <div class="search-container">
      <h2>Search for Advice</h2>
      <div class="search-form">
        <input type="text" id="search-input" placeholder="Enter search term...">
        <button id="search-btn">Search</button>
      </div>
      <div id="search-results"></div>
    </div>
  </div>
  
  <script src="script.js"></script>
</body>
</html>

Step 4: Test Your Implementation

Open your HTML file in a browser to test your advice application. You should be able to:

  • Get a random advice slip by clicking the "Get Advice" button
  • Search for advice slips containing specific terms
  • View the advice ID for each slip

Error Handling

Common Errors

  • 404 Not Found: Invalid endpoint or advice ID not found
  • Network Errors: Connection issues or API downtime

Caching Issues

The Advice Slip API responses may be cached by browsers, which can result in the same advice being returned for multiple requests. To avoid this, we've added a timestamp parameter to the request URL.

API Details

Base URL
https://api.adviceslip.com
Authentication
None
Documentation
Official Docs

Endpoints

  • GET
    /advice

    Get a random advice slip

  • GET
    /advice/{slip_id}

    Get a specific advice slip by ID

    Parameters
    • slip_id*
      number - The ID of the advice slip to retrieve
  • GET
    /advice/search/{query}

    Search for advice slips containing a specific term

    Parameters
    • query*
      string - The search term to look for in advice slips