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

The Quotes API is free, open-source. Working with Node, rest API pattern. MongoDB database. Return all quotes, random quote, random with min length, max length.

License

Notifications You must be signed in to change notification settings

vkhangstack/api-quotes

Repository files navigation

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

About

The Quotes API is free, open-source. Working with Node, rest API pattern. MongoDB database. Return all quotes, random quote, random with min length, max length.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published