Quotable API Documentation

repository·master·Indexed 24 days ago

https://github.com/lukepeavey/quotable

A free, open-source RESTful API for accessing a database of quotes, authors, and tags. Version 0.3.0 provides endpoints to retrieve random quotes, list paginated quotes, search for authors via autocomplete, and perform advanced full-text searches using Atlas Search. Features include filtering by tags, author slugs, and character length, with a rate limit of 180 requests per minute per IP address.

Tokens
4K
Snippets
13
Records
20
Agent score
83%

What's inside quotable

  1. Overview of Quotable API

    master

    Quotable is a free, open-source quotations API. It allows developers to retrieve random quotes, list quotes, search for authors, and more.

    Base URL: https://api.quotable.io

    Rate Limiting: The API enforces a rate limit of 180 requests per minute per IP address. Exceeding this limit will result in a 429 error.

  2. Advanced query syntax for the `query` parameter

    master

    When using the query parameter, you can perform complex searches using logical operators and field-specific prefixes.

    Supported Fields:

    • content (default search path)
    • author
    • tags

    Syntax Examples:

    • Logical Operators: term1 AND term2, term1 OR term2, NOT term1
    • Field Prefixes: author:john, tags:wisdom
    • Grouping: author:adams AND (freedom OR justice)
    • Exact Phrase: "exact phrase here"
  3. Run the Quotable server

    master

    The Quotable server is initialized by executing the entrypoint script. It requires a MongoDB connection and uses the PORT environment variable to determine which port to listen on. If PORT is not provided, it defaults to 4000.

    To run the server, ensure your environment variables (including database connection strings) are configured via a .env file or your shell environment, then execute the script.

  4. Get random quotes with filters

    master

    The /quotes/random endpoint returns an array of random quotes matching your specified criteria. Unlike paginated endpoints, this returns a simple JSON array of quote objects without pagination metadata.

    Query Parameters

    ParameterTypeDescription
    limitintegerThe maximum number of random quotes to return (defaults to 1).
    querystringA search query for full-text search. Supports advanced syntax (see Advanced Querying).
    tagsstringA list of tags separated by a comma (,) or pipe (|).
    authorstringOne or more author slugs, separated by a pipe (|).
    minLengthintegerMinimum quote length in characters.
    maxLengthintegerMaximum quote length in characters.

    Advanced Querying

    If enableAdvancedQuery is active (default), the query parameter supports MongoDB Atlas Search queryString syntax:

    • Field Prefixes: Target specific fields using <field>:<search term>. Supported fields are content, author, and tags.
    • Logical Operators: Use AND, OR, and NOT to combine terms.
    • Grouping: Use parentheses () to group expressions.
    • Exact Phrases: Wrap a term in double quotes ("phrase") or single quotes ('phrase') to search for an exact match.

    Example: query=author:adams AND (freedom OR justice) matches quotes where the author includes "adams" AND the content contains either "freedom" or "justice".

    Limits:

    • Maximum of 5 logical operators.
    • Maximum of 3 prefixed terms.
    • Maximum query length of 150 characters.
  5. Filter quotes by author

    master

    To filter random quotes by a specific author, use the author parameter.

    • Format: Use author slugs.
    • Multiple Authors: If you want to retrieve quotes from multiple authors, separate the slugs using a pipe (|).
    • Note: Do not use commas to separate multiple authors; this will result in a 400 Bad Request error.

    Example: author=albert-einstein|mark-twain

  6. Search Examples for /search/quotes

    master

    Common usage patterns for the search endpoint:

    • Keyword search: GET /search/quotes?query=life+happiness
    • Author search: GET /search/quotes?query=Kennedy&fields=author
    • Exact phrase search: GET /search/quotes?query="divided house"
  7. Examples for Get Random Quotes

    master

    Use these examples to construct your requests to the /quotes/random endpoint:

    Get 3 random quotes:

    GET /quotes/random?limit=3

    Random quote with tags "technology" AND "famous-quotes":

    GET /quotes/random?tags=technology,famous-quotes

    Random quote with tags "History" OR "Civil Rights":

    GET /quotes/random?tags=history|civil-rights

    Random quote with a maximum length of 50 characters:

    GET /quotes/random?maxLength=50

    Random quote with a length between 100 and 140 characters:

    GET /quotes/random?minLength=100&maxLength=140
  8. Search Authors Examples

    master

    Common usage patterns for the /search/authors endpoint:

    Search for specific name:

    GET /search/authors?query=Einstein

    Autocomplete search:

    GET /search/authors?query=Einst

    Multi-term search (e.g., John Adams):

    GET /search/authors?query=john+adams
  9. List Quotes via GET /quotes

    master

    Retrieve a paginated list of quotes. You can filter results by length, tags, and author, and control sorting and pagination.

    Query Parameters

    ParamTypeDescription
    maxLengthIntMaximum character length
    minLengthIntMinimum character length
    tagsStringFilter by tags. Use a comma (,) for AND logic (must have all tags) or a pipe (|) for OR logic (must have at least one). Tag names are case-insensitive.
    authorStringFilter by author name or slug. Use a pipe (|) for multiple authors.
    authorIdStringdeprecated - Use author instead.
    sortByenumSort field. Default: dateAdded. Values: dateAdded, dateModified, author, content.
    orderenumSort order. Values: asc, desc. Default depends on sortBy (strings default to asc, numbers/dates to desc).
    limitIntResults per page (Min: 1, Max: 150, Default: 20).
    pageIntPage number (Min: 1, Default: 1).

    Response Format

    {
      count: number,
      totalCount: number,
      page: number,
      totalPages: number,
      lastItemIndex: number,
      results: Array<{
        _id: string,
        content: string,
        author: string,
        authorSlug: string,
        length: number,
        tags: string[]
      }>
    }
    GET /quotes?tags=love|happiness
  10. Search for quotes via GET /search/quotes

    master

    Use the GET /search/quotes endpoint to search for quotes by keywords, content, or author name. This endpoint is powered by Atlas Search and is optimized for search bar UIs.

    Key features:

    • Relevance Scoring: Results are automatically sorted by relevance score.
    • Exact Phrase Matching: Wrap your query in double quotes (e.g., "phrase") to search for an exact match.
    • Fuzzy Search: Supports minor typos and misspellings by adjusting fuzzyMaxEdits and fuzzyMaxExpansions.