rudimentary integration between rest api and client -- allProducts fetches product data from database. to do: map onto card components

This commit is contained in:
Mikayla Dobson
2022-10-07 18:33:10 -05:00
parent 3ec9af3b4e
commit 93671bfb43
3 changed files with 23 additions and 1 deletions

View File

@@ -15,4 +15,7 @@ Payment information will be supported through the Stripe API, with session suppo
## Accessing the Project and its REST API Online ## Accessing the Project and its REST API Online
1. The REST API for this project is exposed at https://mikayla-spice-market-api.herokuapp.com/ 1. The REST API for this project is exposed at https://mikayla-spice-market-api.herokuapp.com/
2. The client site will be hosted on Netlify and is not online as of yet. 2. The client site will be hosted on Netlify and is not online as of yet.
## Accessing API Documentation
The Swagger docs for this project can be accessed at https://mikayla-spice-market-api.herokuapp.com/api-docs/

View File

@@ -1,4 +1,19 @@
import { useEffect, useState } from "react"
import { getAllProducts } from "../../util/apiUtils";
export default function AllProducts() { export default function AllProducts() {
const [productData, setProductData] = useState<Response>();
useEffect(() => {
getAllProducts()
.then(res => res.json())
.then(res => setProductData(res));
}, [])
useEffect(() => {
console.log(productData);
}, [productData])
return ( return (
<h1>All Products!</h1> <h1>All Products!</h1>
) )

View File

@@ -0,0 +1,4 @@
export const getAllProducts = async () => {
const response = await fetch("https://mikayla-spice-market-api.herokuapp.com/product");
return response;
}