Code Monkey home page Code Monkey logo

bangtan-api's Introduction

BTS QUOTES API

Simple Node.js API using Express framework to retrieve inspirational quotes from BTS
Production Host: Heroku
✨Demo: https://bts-quotes-api.herokuapp.com/

🥯 API endpoints

GET

Endpoints Description Example
GET/quotes return all quotes https://bts-quotes-api.herokuapp.com/quotes
GET/quote/random return a random quote https://bts-quotes-api.herokuapp.com/quote/random
GET/quote/id/:id return quote by its ID https://bts-quotes-api.herokuapp.com/quote/id/:id
GET/quote/member/:member return an array of quotes by member https://bts-quotes-api.herokuapp.com/quote/member/:member
GET/quote/total return total number of quotes https://bts-quotes-api.herokuapp.com/quote/total

POST

POST/quotes

Post new quote to the collection

Request body:

{
    "quote" : " ",
    "member" : " ",
    "info" : " "
}

Example call:

curl -X POST -i -H "Content-Type: application/json" -d '{
    "quote" : "This is quote",
    "member" : "RM",
    "info" : "This is info"
}' https://bts-quotes-api.herokuapp.com/quotes

PATCH

PATCH/quote/id/:id

Modify existing quote by its id

id is mandatory in the request body

Example call:

curl -X PATCH -i -H "Content-Type: application/json" -d '{
  "id" : "1",
  "info": "This is how you modify info for quote id 1"
}' https://bts-quotes-api.herokuapp.com/quote/id/1 

🥨 Usage

Example: Get a random quote

fetch:

fetch('https://bts-quotes-api.herokuapp.com/quote/random')
    .then(response => response.json())
    .then(data => {
        console.log(data.quote + ' - ' + data.member);
    }).catch(err => console.log(err));

JQuery:

$.getJSON('https://bts-quotes-api.herokuapp.com/quote/random', function(data){
    console.log(data.quote + ' - ' + data.member);
})

async/await:

async function getRandom(){
    const response = await fetch('https://bts-quotes-api.herokuapp.com/quote/random');
    const data = await response.json();
    console.log(data.quote + ' - ' + data.member);
}
getRandom()

🍞 Local Development

Install and run

# clone the repo
$ git clone https://github.com/oanhgle/bangtan-api
$ cd bangtan-api
# install the dependencies
$ npm install 
# start the server
$ npm start

The server will run at http://localhost:3000/

Available scripts

Start the application npm start
Start the development live-reload server npm run dev

🧀 Lisence

License

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.