Giter Club home page Giter Club logo

well300 / quotes-api Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 3.0 72 KB

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.

Home Page: https://quotes-api-self.vercel.app/quote

License: Other

JavaScript 100.00%
quote-api quote-generator

quotes-api's Introduction

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. ๐Ÿ“„โš–๏ธ

quotes-api's People

Contributors

well300 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.