QuoteYeti API
This quote API was created as a backend for one of freeCodeCamp's intermediate front end development projects, the Random Quote Machine.
Unfortunately, I couldn't find any solid APIs with the options I was looking for--and it's obviously fun to create your own API--so here it is. Feel free to use it for your projects, report any issues, open pull requests, etc.
It was built on Node.js with Express.js and MongoDB (native driver).
API Endpoints
I will try to make a nice documentation to make your life easier.
Method | Route | Description |
---|---|---|
POST | /quotes | Add a new quote |
GET | /quotes/:num? | Get random quotes, limited to :num results (default is 1) |
GET | /quotes/search/:query/:num? | Search for quotes, limited to :num results (default is 1) |
GET | /quotes/:id | Get a single quote by :id |
PUT | /quotes/:id | Update quote |
DELETE | /quotes/:id | Delete quote |
GET | /categories | Get all the categories |
GET | /categories/search/:query/:num? | Search for categories, limited to :num results (default is 1) |
GET | /quotes/on/:category | Get all the quotes under :category |
GET | /authors | Get all the authors |
GET | /authors/search/:query/:num? | Search for authors, limited to :num results (default is 1) |
GET | /quotes/by/:author | Get all the quotes by :author |
Example Usage
Get a random quote:
// Using the fetch API
fetch('http://localhost:3000/quotes')
.then(res => res.json())
.then((res) => {
const { author, quote, categories } = res[0];
console.log(`${quote} - by ${author.name}`);
});
// Using good old jQuery
$.getJSON('http://localhost:3000/quotes', (res) => {
const { author, quote, categories } = res[0];
console.log(`${quote} - by ${author.name}`);
});