Skip to content
Random Quotes API
JavaScript
Branch: master
Clone or download

Latest commit

lukePeavey Fix: failing test
Update the test for `/quotes/:id`... add the `length` and `tags` fields to expected
response.
Latest commit a808ceb Feb 11, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Update CircleCI workflow (#20) Jan 31, 2020
.vscode Add CircleCI configuration Jun 29, 2019
__tests__ Fix: failing test Feb 11, 2020
data/sample
scripts Update CircleCI workflow (#20) Jan 31, 2020
src Refactor: controllers Feb 11, 2020
.eslintignore
.eslintrc.json Update package details Jul 1, 2019
.gitignore Add feature tags (#17) Jan 28, 2020
.prettierrc.json
LICENCE.md Add licence Jun 14, 2019
README.md Refactor: controllers Feb 11, 2020
contributing.md Add feature tags (#17) Jan 28, 2020
jest.config.js Fix: failing test Feb 11, 2020
package-lock.json Chore: update packages Feb 11, 2020
package.json Chore: update packages Feb 11, 2020

README.md

Quotable

A REST API for famous quotes

I originally built this for a freeCodeCamp project, and decided to publish for others to use as well. The database currently includes over 1500 quotes by 800 authors.

Table of contents:

API Documentation

Get random quote

Returns a single random quote from the database

Query parameters

param type Description
maxLength Int The maximum Length in characters ( can be combined with minLength )
minLength Int The minimum Length in characters ( can be combined with maxLength )
tags String Filter random quote by tag(s). 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 either of the provided tags.

Request

https://api.quotable.io/random

Response

{
  _id: string,
  content: string,
  author: string,
  tags: [string],
  length: number
}

List Quotes

Get a paginated list of all quotations in the database. This method supports several filter and sorting options.

Query parameters

param type Description
author String Filter quotes by author name. Supports fuzzy search.
authorId String Filter quotes by author ID.
limit Int The number of quotes to return per request. (for pagination).
skip Int The number of items to skip (for pagination).
maxLength Int The maximum Length in characters ( can be combined with minLength )
minLength Int The minimum Length in characters ( can be combined with maxLength )
tags String Filter quotes by tag(s). 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 either of the provided tags.

Request

https://api.quotable.io/quotes

Response

{
  // The number of quotes returned by this request
  count: number,
  // The total number of quotes matching this request
  totalCount: number
  // The index of the last quote returned. When paginating through results,
  // this value would be used as the `skip` parameter when requesting the next
  // "page" of results.
  lastItemIndex: number
  // The array of quotes
  results: {_id: string, content: string, author: string, tags: [string], length:}[]
}

Get Quote By ID

Get a quote by its ID

Request

https://api.quotable.io/quotes/:id

Response

{
  _id: string,
  content: string,
  author: string,
  tags: [string],
  length: number
}

List Authors

Get a paginated list of all authors in the database. This method supports several filter and sorting options.

Query parameters

param type Description
name String Search for authors by name. Supports fuzzy search.
sortBy enum: ['name', 'quoteCount'] The field used to sort authors. Default is 'name'
sortOrder enum: ['asc', 'desc'] The order results are sorted in. Default is 'asc'
limit Int The number of authors to return per request. (for pagination)
skip Int The number of items to skip (for pagination)

Request

https://api.quotable.io/authors

Response

{
  // The number of authors return by this request.
  count: number,
  // The total number of authors matching this request.
  totalCount: number,
  // The index of the last item returned. When paginating through results,
  // this value would be used as the `skip` parameter when requesting the next
  // "page" of results. It will be set to `null` if there are no additional results.
  lastItemIndex: number | null,
  // The array of authors
  results: {_id: string, name: string, quoteCount: string}[]
}

Get Author By ID

Get all quotes a specific author

Request

https://api.quotable.io/authors/:id

Response

{
  _id: string,
  // The author name
  name: string,
  // The total number of quotes by this author
  quoteCount: number,
  // The array of quotes by this author
  quotes: {_id: string, content: string, author: string}[]
}

Get Tags

Get list of available tags

Request

https://api.quotable.io/tags

Response

{
  // The number of all tags by this request
  count: number,
  // The array of tags
  results: {_id: string, name: string}[]
}

Usage

Get a random quote (fetch)

fetch('https://api.quotable.io/random')
  .then(response => response.json())
  .then(data => {
    console.log(`${data.content}${data.author}`)
  })

Get a random quote (async/await)

async function randomQuote() {
  const response = await fetch('https://api.quotable.io/random')
  const data = await response.json()
  console.log(`${data.content}${data.author}`)
}
randomQuote()

Get a random quote (JQuery)

$.getJSON('https://api.quotable.io/random', function(data) {
  console.log(`${data.content}${data.author}`)
})

Live Examples

Basic Random Quote (CodePen)

React Random Quote (CodeSandbox)

Contributing

All feedback and contributions are welcome!

You can’t perform that action at this time.