Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Latest commit

 

History

History
132 lines (95 loc) · 3.32 KB

README.md

File metadata and controls

132 lines (95 loc) · 3.32 KB

API Quotes

The Quotes API is free, open source. It is built from the needs of a coder to call from the web Portfolio. MongoDB database.

Code Quality

Quality gate

SonarCloud

GitHub license

Document

Server

Name URL Description
Staging https://stage-api-quotes.herokuapp.com/ Synced with the stating branch of this repository
Production "" The primary API server

API Reference

Get list quotes

GET /api/quotes

Return all quotes

Example request

http://localhost:3000/api/quotes

Response

[
  {
      _id: oid,
      quote: String,
      author: String,
      tags: [],
      length: Number,
      createdAt: Date,
      updatedAt: Date
      __v: 0
  }
...
]

Get random quote

GET /api/query

Query parameters

param type Description
quote String Set quote=random for random quote
max Int The maximum Length in characters ( can be combined with min )
min Int The minimum Length in characters ( can be combined with max )
{
    _id: oid,
    quote: String,
    author: String,
    tags: [],
    length: Number,
    createdAt: Date,
    updatedAt: Date
    __v: 0
}

Examples

Random Quote try in browser

GET /api/query?quote=random

Random Quote with a maximum length of 50 characters try in browser

GET /api/query?quote=random&max=50

Random Quote with a minium length of 50 characters try in browser

GET /api/query?quote=random&min=50

Random Quote with a length between 50 and 140 characters try in browser

GET /api/query?quote=random&min=50&max=140

Usage on localhost

Get a random quote (fetch)

fetch("http://localhost:3000/api/query?quote=random")
  .then((response) => response.json())
  .then((data) => {
    console.log(`${data.quote}${data.author}`);
  });

Get a random quote (async/await)

async function randomQuote() {
  const response = await fetch("http://localhost:3000/api/query?quote=random");
  const data = await response.json();
  console.log(`${data.quote}${data.author}`);
}
randomQuote();

Get a random quote (JQuery)

$.getJSON("http://localhost:3000/api/query?quote=random", function (data) {
  console.log(`${data.quote}${data.author}`);
});