HOW TO USE IT
Below is documentation on examples to check out on how you can use this fake coffee API to get the data you want, enjoy!
Get all products
fetch("https://fake-coffee-api.vercel.app/api") .then((res) => res.json()) .then((data) => console.log(data));
You can filter for example by name, region, price if you send a JSON body in with your get method. Example using postman send in a body containing what you are looking for using GET method: { id:1 }
Get a single product
fetch("https://fake-coffee-api.vercel.app/api/1") .then((res) => res.json()) .then((data) => console.log(data));
Search by id
Limit results
fetch("https://fake-coffee-api.vercel.app/api?limit=2") .then((res) => res.json()) .then((data) => console.log(data));
Limit search to specified number of docs
Sort results
fetch("https://fake-coffee-api.vercel.app/api?sort=desc") .then((res) => res.json()) .then((data) => console.log(data));
Works with 'desc' or 'asc'
Update a product
fetch("https://fake-coffee-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));
It will return an object with fictive changes, nothing will be altered in the database. PUT will change the fields you sent in and change the rest to empty. PATCH will change the fields you sent in and leave the others as they were before.
Add a new product
fetch("https://fake-coffee-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));
The product will not be added to the database. But if you sent the request correctly it will return a confirmation of a fake created product.
Delete a product
fetch('https://fake-coffee-api.vercel.app/api/1,{method:"DELETE"}') .then((res) => res.json()) .then((data) => console.log(data));
The product will not be deleted on the database. But if you sent the request correctly it will return a fake deleted product.