Skip to content

ArvidGardebo/fake-coffee-brand-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

79bb387 · Apr 19, 2023
Apr 11, 2023
Apr 5, 2023
Apr 10, 2023
Apr 19, 2023
Apr 6, 2023
Apr 13, 2023
Apr 10, 2023
Apr 6, 2023
Apr 10, 2023
Apr 3, 2023
Apr 12, 2023
Apr 10, 2023
Apr 10, 2023
Apr 10, 2023

Repository files navigation

Fake Coffee Api

Fake coffee api is a free online REST API that you can use whenever you need Pseudo-real data without running any server-side code. It's awesome for teaching purposes, sample codes, tests, coffee website etc.

Resources

Check out our documentation at https://fake-coffee-api.vercel.app/ to learn more on how to use our API.

How to use

Get all products

fetch("https://fake-coffee-brand-api.vercel.app/api")
  .then((res) => res.json())
  .then((data) => console.log(data));

Get a single product

fetch("https://fake-coffee-brand-api.vercel.app/api/1")
  .then((res) => res.json())
  .then((data) => console.log(data));

Limit results

fetch("https://fake-coffee-brand-api.vercel.app/api?limit=2")
  .then((res) => res.json())
  .then((data) => console.log(data));

Sort results

sort in descending order

fetch("https://fake-coffee-brand-api.vercel.app/api?sort=desc")
  .then((res) => res.json())
  .then((data) => console.log(data));

sort in ascending order

fetch("https://fake-coffee-brand-api.vercel.app/api?sort=asc")
  .then((res) => res.json())
  .then((data) => console.log(data));

Update a product

fetch("https://fake-coffee-brand-api.vercel.app/api/1", {
  method: "PUT",
  body: JSON.stringify({
    name: "Golden sunset",
    description: "A lovely taste of the sun",
    price: 99.99,
    region: "Africa",
  }),
})
  .then((res) => res.json())
  .then((data) => console.log(data));

OR;

fetch("https://fake-coffee-brand-api.vercel.app/api/1", {
  method: "PATCH",
  body: JSON.stringify({
    name: "Golden sunset",
    descriptop: "A lovely taste of the sun",
    price: 99.99,
    region: "Africa",
  }),
})
  .then((res) => res.json())
  .then((data) => console.log(data));

/* will return
[
  {
    id:5,
    name: 'new name',
    description: 'new description'
    price: 'new price',
    region: 'new region'
  }
]
*/

Note: Edited data will not really be updated into the database.

Add new product

fetch("https://fake-coffee-brand-api.vercel.app/api", {
  method: "POST",
  body: JSON.stringify({
    name: "Heavenly Spice",
    description: "Comforting",
    price: 89.99,
    region: "South Asia",
  }),
})
  .then((res) => res.json())
  .then((data) => console.log(data));

/* will return
[
  {
    id:21,
    name:'Heavenly Spice',
    description:'Comforting',
    price:89.99,
    region:'South Asia'
  }
]
*/

Note: Posted data will not really insert into the database and just return a fake id.

Delete a product

fetch('https://fake-coffee-brand-api.vercel.app/api/1,{method:"DELETE"}')
  .then((res) => res.json())
  .then((data) => console.log(data));

Nothing will delete on the database.

All available routes

Products

{
    id:Number,
    name:String,
    description:String,
    price:Number,
    region:String,
    weight:Number,
    flavor_profile:Array,
    grind_option:Array,
    roast_level:Number,
}

GET

  • /api (get all products)
  • /api/1 (get specific product based on id)
  • /api?limit=5 (limit return results )
  • /api?sort=desc (asc or desc get products in ascending or descending orders)

PUT/PATCH

  • api/1

POST

  • api

DELETE

  • api/1