Git Product home page Git Product logo

samaya-quotes-api's Introduction

Samaya-Quotes-API

This repository contains the quotes used by Samaya Chrome Extension. Install Chrome Extension

API Structure

The metadata.json file contains all the required information for the API. The quotes are seperated into pages to minimize network data usage. Featured array in metadata contains page No of featured quotes.

{
    "totalPages": 3,
    "featured": [
        1,
        3
    ]
}

Usage

  1. Call metadata endpoint to get info regarding the API
https://bibhuticoder.github.io/samaya-quotes-api/quotes/metadata.json
// sample response
{
    "totalPages": 5,
    "featured": [
        4,
        5
    ]
}
  1. Get quotes from specific page (eg: 2)
https://bibhuticoder.github.io/samaya-quotes-api/quotes/2.json
// sample response
[
    {
        "text": "सुरू गर्ने तरीका भनेको कुरा गर्न छोड्नु र गर्न थाल्नु हो",
        "author": "Walt Disney"
    },
    {
        "text": "पैसाको अभाव भन्नु केवल बाहना मात्र हो, तिमीसंग स्पष्ट लक्ष्यको अभाव भएको हो ।",
        "author": null
    },
    {
        "text": "परिश्रम त्यो साँचो हो जसले भाग्यको ढोका खोल्दछ ।",
        "author": null
    }
]

Example(JavaScript)

    function getRandomQuote() {
        fetch('https://bibhuticoder.github.io/samaya-quotes-api/quotes/metadata.json').then(r => r.json()).then(metadata => {
            let randomPage = random(1, metadata.totalPages);
            fetch('https://bibhuticoder.github.io/samaya-quotes-api/quotes/2.json' + randomPage + '.json').then(r => r.json()).then(quotesData => {
                let randomQuote = quotesData[random(0, quotesData.length - 1)];
                // you got the quote 😀
            })
        })
    }

    function random(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

View Quotes

https://bibhuticoder.github.io/samaya-quotes-api

samaya-quotes-api's People

Contributors

bibhuticoder avatar destarxis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

destarxis

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.