### Install Project Dependencies Source: https://github.com/lukepeavey/quotable/blob/master/CONTRIBUTING.md Install all necessary project dependencies using npm. Ensure you have Node.js and npm installed and meet the version requirements. ```shell $ npm install ``` -------------------------------- ### Start the Development Server Source: https://github.com/lukepeavey/quotable/blob/master/CONTRIBUTING.md Start the Quotable API server in development mode. The server includes automatic restarts for code changes. ```shell $ npm run start:dev ``` -------------------------------- ### List Quotes with Pagination Source: https://github.com/lukepeavey/quotable/blob/master/README.md Get the first page of quotes, with a specified number of results per page. This example shows how to request the first page with 20 results. ```HTTP GET /quotes?page=1 ``` -------------------------------- ### Quotable API Usage Examples Source: https://context7.com/lukepeavey/quotable/llms.txt Demonstrates the usage of the previously defined functions to fetch a random quote, quotes by a specific author, and search for quotes. These examples show how to call the functions and log the results. ```javascript // Usage examples (async () => { // Get a random quote const quote = await getRandomQuote(); console.log(`"${quote.content}" - ${quote.author}`); // Get quotes by Einstein const einsteinQuotes = await getQuotesByAuthor('albert-einstein'); console.log(`Found ${einsteinQuotes.pagination.totalCount} quotes by Einstein`); // Search for quotes about wisdom const searchResults = await searchQuotes('wisdom'); console.log(`Found ${searchResults.totalCount} quotes matching "wisdom"`); })(); ``` -------------------------------- ### Search by Keywords Source: https://github.com/lukepeavey/quotable/blob/master/README.md This example demonstrates searching for quotes containing specific keywords. The API will return results that include any of the provided keywords. ```HTTP GET /search/quotes?query=life happiness ``` -------------------------------- ### Get Quote By ID Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieve a single quote using its unique ID. Returns a 404 error if the quote is not found. Includes an example of checking the HTTP status code. ```bash curl "https://api.quotable.io/quotes/abc123" ``` ```bash curl -w "\nHTTP Status: %{http_code}\n" "https://api.quotable.io/quotes/nonexistent-id" ``` -------------------------------- ### GET /quotes Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve quotes with options for pagination, tags, and author filtering. ```APIDOC ## GET /quotes ### Description Retrieve a list of quotes. Supports filtering by tags (OR and AND logic) and author slug, as well as pagination. ### Method GET ### Endpoint /quotes ### Query Parameters - **page** (integer) - Optional - The page number of results to retrieve. - **limit** (integer) - Optional - The number of results to return per page. Defaults to 20. - **tags** (string) - Optional - Comma-separated tags for AND logic, or pipe-separated tags for OR logic. Example: `love|happiness` for OR, `technology,famous-quotes` for AND. - **author** (string) - Optional - The slug of the author to filter quotes by. Example: `albert-einstein`. ### Request Example ```json { "example": "GET /quotes?page=2" } ``` ### Response #### Success Response (200) - **results** (array) - An array of quote objects. - **page** (integer) - The current page number. - **totalPages** (integer) - The total number of pages available. - **totalQuotes** (integer) - The total number of quotes matching the query. #### Response Example ```json { "example": "{\"results\": [{\"_id\": \"5f44713605b0f90019828e1d\", \"content\": \"The greatest glory in living lies not in never falling, but in rising every time we fall.\", \"author\": \"Nelson Mandela\", \"length\": 110, \"tags\": [\"inspirational\", \"life\", \"motivation\"], \"authorSlug\": \"nelson-mandela\", \"dateAdded\": \"2020-08-24\", \"dateModified\": \"2020-08-24\"}], \"page\": 1, \"totalPages\": 10, \"totalQuotes\": 197}" } ``` ``` -------------------------------- ### Get Quotes by Tags (AND) Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve quotes that match all of the specified tags using the AND operator (comma). ```HTTP GET /quotes?tags=technology,famous-quotes ``` -------------------------------- ### Search by Author Source: https://github.com/lukepeavey/quotable/blob/master/README.md This example shows how to search for quotes specifically by an author's name. The `fields` parameter is set to 'author' to restrict the search to that field. ```HTTP GET /search/quotes?query=Kennedy&fields=author ``` -------------------------------- ### Get Quotes by Page Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve quotes for a specific page, with a default of 20 results per page. Use this to paginate through quotes. ```HTTP GET /quotes?page=2 ``` -------------------------------- ### Get Single Author by Slug Source: https://github.com/lukepeavey/quotable/blob/master/README.md Fetch details for a specific author using their unique slug. This is an efficient way to retrieve information about a known author. ```HTTP GET /authors?slug=albert-einstein ``` -------------------------------- ### Get Random Quote with Specific Tags (AND) Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve a random quote that matches all specified tags. Tags are comma-separated. ```HTTP GET /quotes/random?tags=technology,famous-quotes ``` -------------------------------- ### GET /quotes/:id Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve a specific quote by its unique ID. ```APIDOC ## GET /quotes/:id ### Description Get a specific quote by its unique ID. ### Method GET ### Endpoint /quotes/:id ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the quote. ### Response #### Success Response (200) - **_id** (string) - The unique identifier of the quote. - **content** (string) - The quotation text. - **author** (string) - The full name of the author. - **length** (number) - The length of the quote (number of characters). - **tags** (array of strings) - An array of tag names for this quote. #### Response Example ```json { "example": "{\"_id\": \"5f44713605b0f90019828e1d\", \"content\": \"The greatest glory in living lies not in never falling, but in rising every time we fall.\", \"author\": \"Nelson Mandela\", \"length\": 110, \"tags\": [\"inspirational\", \"life\", \"motivation\"], \"authorSlug\": \"nelson-mandela\", \"dateAdded\": \"2020-08-24\", \"dateModified\": \"2020-08-24\"}" } ``` ``` -------------------------------- ### Get Specific Author by Slug Source: https://context7.com/lukepeavey/quotable/llms.txt Fetches details of a single author by their slug, including all their associated quotes. The slug is a URL-friendly identifier. ```bash # Get author details with all their quotes curl "https://api.quotable.io/authors/slug/albert-einstein" ``` -------------------------------- ### Get Random Quote with Specific Tags (OR) Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve a random quote that matches any of the specified tags. Tags are pipe-separated. ```HTTP GET /quotes/random?tags=history|civil-rights ``` -------------------------------- ### List Authors Sorted by Name Source: https://github.com/lukepeavey/quotable/blob/master/README.md Get all authors, sorted alphabetically by name in ascending order. This is a common way to browse the author list. ```HTTP GET /authors?sortBy=name ``` -------------------------------- ### Get Random Quote Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve a single random quote from the database. This is the default behavior. ```HTTP GET /quotes/random ``` -------------------------------- ### Get Quotes by Tags (OR) Source: https://github.com/lukepeavey/quotable/blob/master/README.md Fetch quotes that match any of the specified tags using the OR operator (pipe symbol). ```HTTP GET /quotes?tags=love|happiness ``` -------------------------------- ### List All Authors Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve all authors. This endpoint can be used to list authors with options for sorting and filtering, or to get details for specific authors using slugs or IDs. ```HTTP GET /authors ``` -------------------------------- ### Get Quote By ID Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieves a single quote by its unique ID. Returns a 404 error if the quote is not found. ```APIDOC ## GET /quotes/:id ### Description Retrieves a single quote by its unique ID. ### Method GET ### Endpoint /quotes/:id ### Path Parameters - **id** (string) - Required - The unique identifier of the quote. ### Response #### Success Response (200) - **_id** (string) - The unique identifier of the quote. - **content** (string) - The text of the quote. - **author** (string) - The author of the quote. - **authorSlug** (string) - The slugified version of the author's name. - **length** (integer) - The length of the quote. - **tags** (array of strings) - An array of tags associated with the quote. #### Error Response (404) - The requested resource could not be found. #### Response Example (Success) ```json { "_id": "abc123", "content": "Imagination is more important than knowledge.", "author": "Albert Einstein", "authorSlug": "albert-einstein", "length": 46, "tags": ["famous-quotes", "wisdom"] } ``` ``` -------------------------------- ### Get Author by Slug Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve a single author's details using their unique slug. This is useful for fetching author biographies and links. ```HTTP GET /authors/:id ``` -------------------------------- ### Get Quotes by Author Slug Source: https://github.com/lukepeavey/quotable/blob/master/README.md Filter quotes by a specific author using their unique slug identifier. ```HTTP GET /quotes?author=albert-einstein ``` -------------------------------- ### Get Author By Slug API Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieves a single author's details using their unique slug. ```APIDOC ## GET /authors/:id ### Description Get a single Author by their unique slug. This endpoint can be used to retrieve author details such as bio, website link, and profile image. ### Method GET ### Endpoint /authors/:id #### Path Parameters - **id** (string) - Required - The unique slug of the author. ### Response #### Success Response (200) - **_id** (string) - A unique id for this author. - **bio** (string) - A brief, one paragraph bio of the author. Source: wiki API. - **description** (string) - A one-line description of the author. - **link** (string) - The link to the author's wikipedia page or official website. - **name** (string) - The author's full name. - **slug** (string) - A URL-friendly ID derived from the author's name. - **quoteCount** (string) - The number of quotes by this author. ### Response Example ```json { "_id": "5eb021340422290017436722", "bio": "Albert Einstein was a German-born theoretical physicist who developed the theory of relativity, one of the two pillars of modern physics. His work is also known for its influence on the philosophy of science.", "description": "Theoretical physicist and Nobel laureate", "link": "https://en.wikipedia.org/wiki/Albert_Einstein", "name": "Albert Einstein", "slug": "albert-einstein", "quoteCount": "1" } ``` ``` -------------------------------- ### Get Authors by Slug Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieve authors using their unique slug. Supports single slugs or pipe-separated lists for multiple authors. Pagination can be applied using 'page' and 'limit' parameters. ```bash curl "https://api.quotable.io/authors?slug=albert-einstein" ``` ```bash curl "https://api.quotable.io/authors?slug=albert-einstein|abraham-lincoln" ``` ```bash curl "https://api.quotable.io/authors?page=3&limit=50" ``` -------------------------------- ### Get Multiple Authors by Slug Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve multiple authors by providing a pipe-separated list of their slugs. This allows for fetching details of several specific authors in a single request. ```HTTP GET /authors?slug=albert-einstein|abraham-lincoln ``` -------------------------------- ### Get Multiple Random Quotes Source: https://github.com/lukepeavey/quotable/blob/master/README.md Specify the number of random quotes to retrieve using the 'limit' parameter. The maximum limit is 50. ```HTTP GET /quotes/random?limit=3 ``` -------------------------------- ### Get Quote by ID Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve a single quote using its unique ID. This is useful for fetching a specific quote when its ID is known. ```HTTP GET /quotes/:id ``` -------------------------------- ### Get Author By Slug Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieves a single author by their slug along with all their quotes. The slug is a URL-friendly ID derived from the author's name. ```APIDOC ## GET /authors/slug/:slug ### Description Retrieves a single author by their slug along with all their quotes. ### Method GET ### Endpoint /authors/slug/:slug ### Parameters #### Path Parameters - **slug** (string) - Required - The URL-friendly ID of the author. ### Response #### Success Response (200) - **_id** (string) - Unique identifier for the author. - **slug** (string) - URL-friendly identifier for the author. - **name** (string) - The full name of the author. - **link** (string) - A link to the author's Wikipedia page. - **bio** (string) - A short biography of the author. - **description** (string) - A brief description or title for the author. - **quoteCount** (integer) - The number of quotes associated with the author. - **quotes** (array) - An array of quote objects associated with the author. - **_id** (string) - Unique identifier for the quote. - **content** (string) - The text of the quote. - **author** (string) - The name of the author. - **authorSlug** (string) - The slug of the author. - **length** (integer) - The character length of the quote. - **tags** (array) - An array of tags associated with the quote. ### Request Example ```bash curl "https://api.quotable.io/authors/slug/albert-einstein" ``` ### Response Example ```json { "_id": "xyz789", "slug": "albert-einstein", "name": "Albert Einstein", "link": "https://en.wikipedia.org/wiki/Albert_Einstein", "bio": "Albert Einstein was a German-born theoretical physicist who developed the theory of relativity...", "description": "Theoretical Physicist", "quoteCount": 30, "quotes": [ { "_id": "abc123", "content": "Imagination is more important than knowledge.", "author": "Albert Einstein", "authorSlug": "albert-einstein", "length": 46, "tags": ["famous-quotes", "wisdom"] } ] } ``` ``` -------------------------------- ### Search Quotes Endpoint Source: https://github.com/lukepeavey/quotable/blob/master/README.md This is the base HTTP GET endpoint for searching quotes. It is powered by Atlas Search and designed for search bar UIs. ```HTTP GET /search/quotes ``` -------------------------------- ### Get Random Quote by Length Range Source: https://github.com/lukepeavey/quotable/blob/master/README.md Filter random quotes to retrieve one within a specific character length range using 'minLength' and 'maxLength'. ```HTTP GET /quotes/random?minLength=100&maxLength=140 ``` -------------------------------- ### Get Random Quotes Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieve one or more random quotes. Supports filtering by author, tags (AND/OR logic), and quote length. The 'limit' parameter controls the number of quotes returned (max 50). ```bash curl "https://api.quotable.io/quotes/random" ``` ```bash curl "https://api.quotable.io/quotes/random?limit=5" ``` ```bash curl "https://api.quotable.io/quotes/random?tags=technology,famous-quotes" ``` ```bash curl "https://api.quotable.io/quotes/random?tags=history|civil-rights" ``` ```bash curl "https://api.quotable.io/quotes/random?author=albert-einstein" ``` ```bash curl "https://api.quotable.io/quotes/random?author=albert-einstein|abraham-lincoln" ``` ```bash curl "https://api.quotable.io/quotes/random?minLength=100&maxLength=140" ``` -------------------------------- ### Seed the Database Source: https://github.com/lukepeavey/quotable/blob/master/CONTRIBUTING.md Populate your MongoDB database with sample data using the provided npm script. This command uses the data located in the 'data/sample' directory. ```shell $ npm run database:seed data/sample ``` -------------------------------- ### Get random quote Source: https://github.com/lukepeavey/quotable/blob/master/README.md Returns a single random quote from the database. This method is deprecated in favor of Get Random Quotes. ```APIDOC ## GET /random ### Description Returns a single random quote from the database. > ⛔️ This method is deprecated in favor of [Get Random Quotes](#get-random-quotes) ### Method GET ### Endpoint /random ### Query Parameters - **maxLength** (Int) - Optional - The maximum Length in characters ( can be combined with `minLength` ) - **minLength** (Int) - Optional - The minimum Length in characters ( can be combined with `maxLength` ) - **tags** (String) - Optional - Get a random quote with specific tag(s). This takes a list of one or more tag names, separated by a comma (meaning `AND`) or a pipe (meaning `OR`). A comma separated list will match quotes that have **_all_** of the given tags. While a pipe (`|`) separated list will match quotes that have **any one** of the provided tags. Tag names are **not** case-sensitive. Multi-word tags can be kebab-case ("tag-name") or space separated ("tag name") - **author** (String) - Optional - Get a random quote by one or more authors. The value can be an author `name` or `slug`. To include quotes by multiple authors, provide a pipe-separated list of author names/slugs. - **authorId** (String) - Optional - `deprecated`
Same as `author` param, except it uses author `_id` instead of `slug` ### Response #### Success Response (200) - **_id** (string) - The unique identifier for the quote. - **content** (string) - The quotation text. - **author** (string) - The full name of the author. - **authorSlug** (string) - The `slug` of the quote author. - **length** (number) - The length of quote (number of characters). - **tags** (string[]) - An array of tag names for this quote. #### Response Example ```json { "_id": "string", "content": "string", "author": "string", "authorSlug": "string", "length": 0, "tags": [ "string" ] } ``` ``` -------------------------------- ### Run Tests and Linting Source: https://github.com/lukepeavey/quotable/blob/master/CONTRIBUTING.md Execute the test suite to ensure all tests are passing and run the linter to check for code style issues before submitting a pull request. ```shell # Runs tests $ npm run test # Check for lint issues $ npm run lint ``` -------------------------------- ### Get Random Quote Endpoint Source: https://github.com/lukepeavey/quotable/blob/master/README.md Use this endpoint to retrieve a single random quote. Query parameters can filter by length, tags, or author. This method is deprecated in favor of 'Get Random Quotes'. ```http GET /random ``` -------------------------------- ### Set MONGODB_URI Environment Variable Source: https://github.com/lukepeavey/quotable/blob/master/CONTRIBUTING.md Configure the MONGODB_URI environment variable in a .env file at the project root to point to your MongoDB database. Replace with your actual database connection string. ```shell MONGODB_URI= ``` -------------------------------- ### List All Tags Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieve a list of all available tags, including their quote counts. Tags can be used to categorize and filter quotes. Sorting options include by name, quote count, or date added. ```bash # Get all tags (sorted by name by default) curl "https://api.quotable.io/tags" ``` ```bash # Sort by quote count (most popular tags first) curl "https://api.quotable.io/tags?sortBy=quoteCount&order=desc" ``` ```bash # Sort by date added curl "https://api.quotable.io/tags?sortBy=dateAdded&order=desc" ``` -------------------------------- ### List All Tags Source: https://github.com/lukepeavey/quotable/blob/master/README.md Fetches a list of all available tags. Supports sorting by name, dateAdded, dateModified, or quoteCount, with options for ascending or descending order. ```HTTP GET /tags ``` -------------------------------- ### Search Authors by Name Source: https://context7.com/lukepeavey/quotable/llms.txt Search for authors by name with autocomplete support, ideal for search bar UIs. Results are sorted by relevance. Options include disabling autocomplete and adjusting match thresholds. ```bash # Basic author search curl "https://api.quotable.io/search/authors?query=Einstein" ``` ```bash # Autocomplete search (partial name) curl "https://api.quotable.io/search/authors?query=Einst" ``` ```bash # Search with full name curl "https://api.quotable.io/search/authors?query=John%20Adams" ``` ```bash # Disable autocomplete for exact matches curl "https://api.quotable.io/search/authors?query=Kennedy&autocomplete=false" ``` ```bash # Adjust match threshold (1 = match any term, 2 = match at least 2 terms) curl "https://api.quotable.io/search/authors?query=John%20Quincy%20Adams&matchThreshold=2" ``` ```bash # Paginated results curl "https://api.quotable.io/search/authors?query=John&limit=5&page=1" ``` -------------------------------- ### Search Authors by Name Source: https://github.com/lukepeavey/quotable/blob/master/README.md Use this endpoint to search for authors by name. It supports partial matches and returns a list of authors matching the query. ```HTTP GET /search/authors?query=Einstein ``` ```HTTP GET /search/authors?query=Einst ``` ```HTTP GET /search/authors?query=john adams ``` ```HTTP GET /search/authors?query=john quincy adams ``` -------------------------------- ### List All Quotes Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve a paginated list of all quotes. Default sorting is by `_id`. ```HTTP GET /quotes ``` -------------------------------- ### API Server Address Source: https://github.com/lukepeavey/quotable/blob/master/README.md The base URL for accessing the Quotable API. ```text https://api.quotable.io ``` -------------------------------- ### Get Random Quote by Maximum Length Source: https://github.com/lukepeavey/quotable/blob/master/README.md Filter random quotes to retrieve one with a maximum character length specified by 'maxLength'. ```HTTP GET /quotes/random?maxLength=50 ``` -------------------------------- ### Add Upstream Remote and Pull Latest Changes Source: https://github.com/lukepeavey/quotable/blob/master/CONTRIBUTING.md Before working on a new contribution with an existing fork, ensure your local repository is up-to-date by adding the upstream remote and pulling the latest changes from the master branch. ```shell $ git remote add upstream https://github.com/lukePeavey/quotable.git $ git pull upstream master ``` -------------------------------- ### Search Quotes by Keyword Source: https://context7.com/lukepeavey/quotable/llms.txt Perform full-text searches for quotes using keywords, content, or author names. Results are sorted by relevance. Wrap exact phrases in quotes. Supports filtering by specific fields and pagination. ```bash # Basic keyword search curl "https://api.quotable.io/search/quotes?query=technology%20magic" ``` ```bash # Search for exact phrase (wrap in quotes) curl "https://api.quotable.io/search/quotes?query=%22divided%20house%22" ``` ```bash # Search quotes by author name curl "https://api.quotable.io/search/quotes?query=Kennedy&fields=author" ``` ```bash # Search with specific fields (content, author, tags) curl "https://api.quotable.io/search/quotes?query=freedom&fields=content,tags" ``` ```bash # Paginated search results curl "https://api.quotable.io/search/quotes?query=love&limit=10&page=2" ``` ```bash # Advanced query with logical operators curl "https://api.quotable.io/search/quotes?query=author:einstein%20AND%20(knowledge%20OR%20imagination)" ``` -------------------------------- ### Get Random Quotes Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieve one or more random quotes from the database. This endpoint supports filters for tags, quote length, and author. ```APIDOC ## GET /quotes/random ### Description Get one or more random quotes from the database. This method supports several filters that can be used to get random quotes with specific properties (ie tags, quote length, etc.). By default, this methods returns a single random quote. You can specify the number of random quotes to return via the `limit` parameter. > ⚠️ This method is equivalent to the `/random` endpoint. The only difference is the response format: Instead of returning a single `Quote` object, this method returns an `Array` of `Quote` objects. ### Method GET ### Endpoint /quotes/random ### Query Parameters - **limit** (Int) - Optional - The number of random quotes to retrieve. `default: 1`, `min: 1`, `max: 50` - **maxLength** (Int) - Optional - The maximum length in characters (can be combined with `minLength`) - **minLength** (Int) - Optional - The minimum length in characters (can be combined with `maxLength`) - **tags** (String) - Optional - Get a random quote with specific tag(s). This takes a list of one or more tag names, separated by a comma (meaning `AND`) or a pipe (meaning `OR`). A comma separated list will match quotes that have **_all_** of the given tags. While a pipe (`|`) separated list will match quotes that have **any one** of the provided tags. Tag names are **not** case-sensitive. Multi-word tags can be kebab-case ("tag-name") or space separated ("tag name"). - **author** (String) - Optional - Get a random quote by one or more authors. The value can be an author `name` or `slug`. To include quotes by multiple authors, provide a pipe-separated list of author names/slugs. - **authorId** (String) - Optional - `deprecated` Same as `author` param, except it uses author `_id` instead of `slug` ### Response #### Success Response (200) - **_id** (string) - The unique identifier for the quote. - **content** (string) - The quotation text. - **author** (string) - The full name of the author. - **authorSlug** (string) - The `slug` of the quote author. - **length** (number) - The length of the quote in characters. - **tags** (Array) - An array of tag names associated with the quote. ### Response Example ```json [ { "_id": "string", "content": "string", "author": "string", "authorSlug": "string", "length": 0, "tags": [ "string" ] } ] ``` ### Examples Get random quote: ```HTTP GET /quotes/random ``` Get 3 random quotes: ```HTTP GET /quotes/random?limit=3 ``` Random Quote with tags "technology" **`AND`** "famous-quotes": ```HTTP GET /quotes/random?tags=technology,famous-quotes ``` Random Quote with tags "History" **`OR`** "Civil Rights": ```HTTP GET /quotes/random?tags=history|civil-rights ``` Random Quote with a maximum length of 50 characters: ```HTTP GET /quotes/random?maxLength=50 ``` Random Quote with a length between 100 and 140 characters: ```HTTP GET /quotes/random?minLength=100&maxLength=140 ``` ``` -------------------------------- ### Fetch Quotes by Author with Pagination Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieves quotes by a specific author using their slug, with options for pagination (page number and limit). Requires the author's slug and optionally accepts page and limit parameters. ```javascript // Fetch quotes with filters async function getQuotesByAuthor(authorSlug, options = {}) { const { page = 1, limit = 20 } = options; const params = new URLSearchParams({ author: authorSlug, page: page.toString(), limit: limit.toString() }); const response = await fetch(`https://api.quotable.io/quotes?${params}`); const data = await response.json(); return { quotes: data.results, pagination: { page: data.page, totalPages: data.totalPages, totalCount: data.totalCount } }; } ``` -------------------------------- ### Search for a Specific Phrase Source: https://github.com/lukepeavey/quotable/blob/master/README.md To search for an exact phrase, wrap the query in quotes. This ensures results only include quotes that precisely match the specified phrase. ```HTTP GET /search/quotes?query=every good technology is basically magic ``` ```HTTP GET /search/quotes?query=divided house ``` -------------------------------- ### List Tags API Source: https://github.com/lukepeavey/quotable/blob/master/README.md Retrieves a list of all available tags, with options for sorting. ```APIDOC ## GET /tags ### Description Get a list of all tags. ### Method GET ### Endpoint /tags #### Query Parameters - **sortBy** (enum) - Optional - The field used to sort tags. Values: "dateAdded", "dateModified", "name", "quoteCount". Default: "name". - **order** (enum) - Optional - The order in which results are sorted. Values: "asc", "desc". The default order depends on the sortBy field. ### Response #### Success Response (200) - **count** (number) - The number of all tags by this request. - **results** (Array) - The array of tags. - **_id** (string) - Unique identifier for the tag. - **name** (string) - The name of the tag. ### Response Example ```json { "count": 10, "results": [ { "_id": "5efd30451174700017510000", "name": "love" }, { "_id": "5efd30451174700017510001", "name": "inspirational" } ] } ``` ``` -------------------------------- ### List Tags Source: https://context7.com/lukepeavey/quotable/llms.txt Returns a list of all tags with their quote counts. Tags can be used to filter quotes by category. ```APIDOC ## GET /tags ### Description Retrieves a list of all available tags and the number of quotes associated with each tag. ### Method GET ### Endpoint /tags ### Parameters #### Query Parameters - **sortBy** (string) - Optional - Field to sort the tags by. Options: `name`, `quoteCount`, `dateAdded`. Defaults to `name`. - **order** (string) - Optional - Sort order. Options: `asc`, `desc`. Defaults to `asc`. ### Request Example ```bash # Get all tags (sorted by name by default) curl "https://api.quotable.io/tags" # Sort by quote count (most popular tags first) curl "https://api.quotable.io/tags?sortBy=quoteCount&order=desc" # Sort by date added (most recent first) curl "https://api.quotable.io/tags?sortBy=dateAdded&order=desc" ``` ### Response #### Success Response (200) - An array of tag objects. - **_id** (string) - Unique identifier for the tag. - **name** (string) - The name of the tag. - **quoteCount** (integer) - The number of quotes associated with this tag. ### Response Example ```json [ { "_id": "tag123", "name": "business", "quoteCount": 150 }, { "_id": "tag124", "name": "famous-quotes", "quoteCount": 500 } ] ``` ``` -------------------------------- ### Search Quotes Response Structure Source: https://github.com/lukepeavey/quotable/blob/master/README.md The response includes pagination details (count, totalCount, page, totalPages, lastItemIndex) and an array of quote results. Each result contains quote details and author information. ```typescript { // The number of results included in this response. count: number // The total number of results matching this request. totalCount: number // The current page number page: number // The total number of pages matching this request totalPages: number // The 1-based index of the last result included in this response. This shows the // current pagination offset. lastItemIndex: number | null // The array of authors results: Array<{ // A unique id for this author _id: string // A brief, one paragraph bio of the author. Source: wiki API bio: string // A one-line description of the author. Typically it is the person's primary // occupation or what they are know for. description: string // The link to the author's wikipedia page or official website link: string // The authors full name name: string // A slug is a URL-friendly ID derived from the authors name. It can be used as slug: string // The number of quotes by this author quoteCount: string }> } ``` -------------------------------- ### Get Random Quotes Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieves one or more random quotes. Supports filtering by author, tags, and quote length. The `limit` parameter controls the number of quotes returned (max 50). ```APIDOC ## GET /quotes/random ### Description Returns one or more random quotes from the database. Supports filtering by author, tags, and quote length. ### Method GET ### Endpoint /quotes/random ### Query Parameters - **limit** (integer) - Optional - The number of random quotes to return (max 50). - **tags** (string) - Optional - Comma-separated tags for AND logic, or pipe-separated for OR logic. - **author** (string) - Optional - Comma-separated author slugs for AND logic, or pipe-separated for OR logic. - **minLength** (integer) - Optional - Minimum length of the quote. - **maxLength** (integer) - Optional - Maximum length of the quote. ### Response #### Success Response (200) - **_id** (string) - The unique identifier of the quote. - **content** (string) - The text of the quote. - **author** (string) - The author of the quote. - **authorSlug** (string) - The slugified version of the author's name. - **length** (integer) - The length of the quote. - **tags** (array of strings) - An array of tags associated with the quote. #### Response Example ```json [ { "_id": "abc123", "content": "The only way to do great work is to love what you do.", "author": "Steve Jobs", "authorSlug": "steve-jobs", "length": 52, "tags": ["famous-quotes", "inspirational"] } ] ``` ``` -------------------------------- ### List Quotes Source: https://context7.com/lukepeavey/quotable/llms.txt Returns a paginated list of all quotes matching the given query. Supports filtering by author, tags, and length. Results can be sorted by various fields. ```APIDOC ## GET /quotes ### Description Returns a paginated list of all quotes matching the given query. Supports filtering by author, tags, and length. Results can be sorted by various fields. ### Method GET ### Endpoint /quotes ### Query Parameters - **page** (integer) - Optional - The page number to retrieve. - **limit** (integer) - Optional - The number of quotes per page (default is 20). - **author** (string) - Optional - Filter by author slug. Use comma-separated for AND logic, pipe-separated for OR logic. - **tags** (string) - Optional - Filter by tags. Use comma-separated for AND logic, pipe-separated for OR logic. - **minLength** (integer) - Optional - Minimum length of the quote. - **maxLength** (integer) - Optional - Maximum length of the quote. - **sortBy** (string) - Optional - Field to sort by (e.g., 'author', 'content', 'length', 'dateAdded'). - **order** (string) - Optional - Sort order ('asc' or 'desc'). ### Response #### Success Response (200) - **count** (integer) - The number of quotes returned in this page. - **totalCount** (integer) - The total number of quotes available. - **page** (integer) - The current page number. - **totalPages** (integer) - The total number of pages. - **lastItemIndex** (integer) - The index of the last item on the current page. - **results** (array of objects) - An array of quote objects. - **_id** (string) - The unique identifier of the quote. - **content** (string) - The text of the quote. - **author** (string) - The author of the quote. - **authorSlug** (string) - The slugified version of the author's name. - **length** (integer) - The length of the quote. - **tags** (array of strings) - An array of tags associated with the quote. #### Response Example ```json { "count": 20, "totalCount": 2000, "page": 1, "totalPages": 100, "lastItemIndex": 20, "results": [ { "_id": "abc123", "content": "Quote text here...", "author": "Author Name", "authorSlug": "author-name", "length": 45, "tags": ["wisdom"] } ] } ``` ``` -------------------------------- ### List Authors Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieve a paginated list of all authors. Supports filtering by name or slug, and sorting by name, quote count, or date fields. ```bash curl "https://api.quotable.io/authors" ``` ```bash curl "https://api.quotable.io/authors?sortBy=quoteCount&order=desc" ``` -------------------------------- ### List Quotes Source: https://context7.com/lukepeavey/quotable/llms.txt Retrieve a paginated list of quotes. Supports filtering by author(s), tags (AND/OR logic), and length. Results can be sorted by various fields in ascending or descending order. ```bash curl "https://api.quotable.io/quotes" ``` ```bash curl "https://api.quotable.io/quotes?page=2&limit=50" ``` ```bash curl "https://api.quotable.io/quotes?author=albert-einstein" ``` ```bash curl "https://api.quotable.io/quotes?author=albert-einstein|isaac-newton" ``` ```bash curl "https://api.quotable.io/quotes?tags=love,happiness" ``` ```bash curl "https://api.quotable.io/quotes?tags=love|happiness" ``` ```bash curl "https://api.quotable.io/quotes?sortBy=author&order=asc" ``` ```bash curl "https://api.quotable.io/quotes?sortBy=dateAdded&order=desc" ``` ```bash curl "https://api.quotable.io/quotes?author=albert-einstein&sortBy=content&order=asc" ``` -------------------------------- ### Search Authors Source: https://context7.com/lukepeavey/quotable/llms.txt Search for authors by name with autocomplete support. Designed to power search bar UIs with real-time suggestions. Results are sorted by relevance score. ```APIDOC ## GET /search/authors ### Description Searches for authors by name, with optional autocomplete functionality. Results are sorted by relevance. ### Method GET ### Endpoint /search/authors ### Parameters #### Query Parameters - **query** (string) - Required - The author's name or partial name to search for. - **autocomplete** (boolean) - Optional - If `true` (default), enables autocomplete suggestions. If `false`, performs an exact match search. - **matchThreshold** (integer) - Optional - Sets the threshold for matching terms in the query. `1` matches any term, `2` matches at least two terms. Defaults to `1`. - **limit** (integer) - Optional - The maximum number of results to return per page. Defaults to 20. - **page** (integer) - Optional - The page number of the results to retrieve. Defaults to 1. ### Request Example ```bash # Basic author search curl "https://api.quotable.io/search/authors?query=Einstein" # Autocomplete search (partial name) curl "https://api.quotable.io/search/authors?query=Einst" # Search with full name (exact match) curl "https://api.quotable.io/search/authors?query=John%20Adams&autocomplete=false" # Adjust match threshold curl "https://api.quotable.io/search/authors?query=John%20Quincy%20Adams&matchThreshold=2" # Paginated results curl "https://api.quotable.io/search/authors?query=John&limit=5&page=1" ``` ### Response #### Success Response (200) - **count** (integer) - The number of results on the current page. - **totalCount** (integer) - The total number of results matching the query. - **page** (integer) - The current page number. - **totalPages** (integer) - The total number of pages available. - **lastItemIndex** (integer or null) - The index of the last item on the current page. - **results** (array) - An array of author objects matching the search query. - **_id** (string) - Unique identifier for the author. - **slug** (string) - URL-friendly identifier for the author. - **name** (string) - The full name of the author. - **link** (string) - A link to the author's Wikipedia page. - **bio** (string) - A short biography of the author. - **description** (string) - A brief description or title for the author. - **quoteCount** (integer) - The number of quotes associated with the author. ### Response Example ```json { "count": 1, "totalCount": 1, "page": 1, "totalPages": 1, "lastItemIndex": null, "results": [ { "_id": "xyz789", "slug": "albert-einstein", "name": "Albert Einstein", "link": "https://en.wikipedia.org/wiki/Albert_Einstein", "bio": "Albert Einstein was a German-born theoretical physicist...", "description": "Theoretical Physicist", "quoteCount": 30 } ] } ``` ``` -------------------------------- ### Fetch Random Quote with Error Handling Source: https://context7.com/lukepeavey/quotable/llms.txt Fetches a random quote using the native fetch API. Includes error handling for network issues and non-OK HTTP responses. Ensure the API endpoint is accessible. ```javascript // Fetch random quote using native fetch async function getRandomQuote() { try { const response = await fetch('https://api.quotable.io/quotes/random'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const [quote] = await response.json(); return quote; } catch (error) { console.error('Failed to fetch quote:', error); throw error; } } ``` -------------------------------- ### Search Quotes with Pagination Source: https://context7.com/lukepeavey/quotable/llms.txt Searches for quotes based on a query string, with support for pagination. Accepts the search query and an optional page number. The API uses Atlas Search for efficient querying. ```javascript // Search quotes with pagination async function searchQuotes(query, page = 1) { const params = new URLSearchParams({ query, page: page.toString() }); const response = await fetch(`https://api.quotable.io/search/quotes?${params}`); return response.json(); } ``` -------------------------------- ### Search Authors API Source: https://github.com/lukepeavey/quotable/blob/master/README.md This endpoint allows you to search for authors by name. It is designed to power a search bar for authors that displays autocomplete suggestions as the user types. ```APIDOC ## GET /search/authors ### Description This endpoint allows you to search for authors by name. It is designed to power a search bar for authors that displays autocomplete suggestions as the user types. - Powered by [Atlas Search](https://docs.atlas.mongodb.com/atlas-search/). - Real autocomplete - Results are sorted by score - Parses the query into "terms". Things like initials, prefixes, suffixes, and stopwords are not considered search terms. They will still impact the score of a result, but are not required to match. **Query Parameters** - **query** (String) - Required - The search query - **autocomplete** (Boolean) - Optional - `default: true` Enables autocomplete matching - **matchThreshold** (Int) - Optional - `Min: 1` `Max: 3` `Default: 2` Sets the minimum number of search terms (words) that must match for an author to be included in results. - **limit** (Int) - Optional - `Max: 150` `Default: 20` Maximum number of results per page ### Request Example ```json { "query": "John F. Kennedy" } ``` ### Response #### Success Response (200) - **results** (Array) - An array of author objects matching the search criteria. - **message** (String) - A message indicating the status of the request. - **count** (Int) - The number of authors returned. - **cursor** (String) - A cursor for pagination, if applicable. #### Response Example ```json { "results": [ { "_id": "5eb06a772195fa0017760421", "name": "John F. Kennedy", "slug": "john-f-kennedy", "bio": "John Fitzgerald Kennedy, often referred to by his initials JFK, was an American politician who served as the 35th president of the United States from 1961 until his assassination in November 1963.", "quoteCount": 10 } ], "message": "Authors found successfully.", "count": 1, "cursor": "" } ``` ```