Skip to content

nk-gears/quotable

Repository files navigation

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

Request

https://api.quotable.io/random

Response

{
  _id: string,
  content: string,
  author: string
}

Search Quotes (beta)

Get quotes from the database using various filter and sorting options. All parameters are optional.

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)

Request

https://api.quotable.io/quotes

Response

{
  // The number of quotes returned by this request
  count: number,
  // The total number or 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}[]
}

Get Quote By ID

Get a quote by its ID

Request

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

Response

{
  _id: string,
  content: string,
  author: string
}

Search Authors (beta)

Search the database for authors using various filter/sorting options. All parameters are optional. By default, it returns all authors in alphabetical order.

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 or 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.
  lastItemIndex: number
  // The array of authors
  results: {_id: string, name: string, quoteCount: string}[]
}

Get Author By ID (beta)

Get all quotes a specific author

Request

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

Response

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

Examples

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}`)
}

Get a random quote (JQuery)

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

Contributing

All feedback and contributions are welcome!

About

Random Quotes API

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%