Skip to content

The "Quotes API" πŸ“šβœ‰οΈ is a delightful web service that fetches random quotes from a JSON file and allows users to add new quotes, making it a 🌟✍️ choice for accessing and expanding your collection of inspirational words.

License

Notifications You must be signed in to change notification settings

well300/quotes-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Quotes API

πŸ“œ This is a simple Express.js API that provides a collection of quotes. The quotes are fetched from a JSON file named "quotes.json". The API has two endpoints: /quote and /quote (HTTP GET and POST, respectively).

Example:

Here is a working example of a Quote Generator ✨

Installation

  1. Clone this repository:
git clone https://github.com/well300/quotes-api.git
  1. Install the dependencies:
cd quotes-api
npm install

3.Start the server:

npm start

API Endpoints

GET /quote

Fetches a random quote from the "quotes.json" file and returns it as a JSON response. For example, in your client-side JavaScript code, you can use the fetch function to make a GET request to the /quote endpoint on your server:

fetch('https://quotes-api-self.vercel.app/quote')
  .then(response => response.json())
  .then(data => {
    // Handle the retrieved quote
    console.log(data);
  })
  .catch(error => {
    // Handle any errors
    console.error(error);
  });

Example response:

{
  "quote": "Be the change you wish to see in the world.",
  "author": "Mahatma Gandhi"
}

POST /quote

Adds a new quote to the "quotes.json" file. The request body should contain the quote and author in JSON format.

Example request:

{
  "quote": "It always seems impossible until it's done.",
  "author": "Nelson Mandela"
}

Example response:

{
  "quote": "It always seems impossible until it's done.",
  "author": "Nelson Mandela"
}

Error handling

If an error occurs while fetching or adding a quote, the API will return a JSON response with an "error" property:

{
  "error": "Unable to fetch a quote."
}

License

This project is licensed under the MIT License. πŸ“„βš–οΈ

About

The "Quotes API" πŸ“šβœ‰οΈ is a delightful web service that fetches random quotes from a JSON file and allows users to add new quotes, making it a 🌟✍️ choice for accessing and expanding your collection of inspirational words.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published