Giter Club home page Giter Club logo

quotable's Introduction

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!

quotable's People

Contributors

lukepeavey avatar marekdano avatar aman-maharshi avatar jay-liu-aw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.