Skip to content

An Express API following the MVC pattern. Created and planned in collaboration with @thoughtbyte, @shishkina

Notifications You must be signed in to change notification settings

jlr7245/ada-quotes-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a REST-ful API that serves the favorite quotes of WDI Ada, a General Assembly Web Development Immersive course in NYC.

No keys are needed to access this API.

(Note: This is being used for student exercises & so on, so there may be some... unusual... quotes in the database from time to time.)

Endpoints

The API has two main endpoints: /api/quotes and /api/categories. Here are some sample calls from each and their responses.

GET endpoints

api/quotes

{
    "message": "ok",
    "quotesData": [
        {
            "content": "The expert at anything was once a beginner.",
            "author": "Helen Hayes",
            "id": "4",
            "genre_type": "education"
        },
        {
            "content": "If you want something you never had, you have to do something you've never done!",
            "author": "Unknown",
            "id": "6",
            "genre_type": "motivational"
        },
        /* additional quotes */
    ]
}

api/quotes/:id

{
  "message": "ok",
  "quote": {
    "content": "Hello World",
    "author": "Tim Berners-Lee",
    "id": "16",
    "genre_type": "philosophical"
  }
}

api/categories

{
    "message": "ok",
    "categoriesData": [
        {
            "genre_type": "motivational",
            "id": "1",
            "num_quotes": "1"
        },
        {
            "genre_type": "philosophical",
            "id": "3",
            "num_quotes": "4"
        },
        {
            "genre_type": "education",
            "id": "4",
            "num_quotes": "1"
        },
        /* additional genres */
    ]
}

api/categories/:id

{
  "message": "ok",
  "category": [
    {
      "content": "Who are we, who is each one of us, if not a combinatoria of experiences, information, books we have read, things imagined?",
      "author": "Italo Calvino",
      "genre_type": "literary",
      "id": "9"
    },
    {
      "content": "In search of the difficulty rather than in its clutch. The disquiet of him who lacks an adversary.",
      "author": "Samuel Beckett",
      "genre_type": "literary",
      "id": "11"
    }
  ]
}

Other Endpoints

POST to api/quotes

Quotes can be added to the database like so:

fetch('https://ada-api.herokuapp.com/api/quotes', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    content: e.target.content.value,
    author: e.target.author.value,
    genre_id: e.target.genre_id.value,
  }),
})

PUT to api/quotes/:id

Modify a quote's information in the database.

// where ID is the quote's ID
fetch(`https://ada-api.herokuapp.com/api/quotes/${id}`, {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    content: 'quote content here',
    author: 'quote author here',
    genre_id: 3 // the genre ID must be a number
  }),
})

DELETE to api/quotes/:id

Remove a quote from the database.

// where ID is the quote's ID
fetch(`https://ada-api.herokuapp.com/api/quotes/${id}`, {
  method: 'DELETE',
})

About

An Express API following the MVC pattern. Created and planned in collaboration with @thoughtbyte, @shishkina

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages