Edgio Serverless Functions allow you to create APIs without using a Javascript framework. This example is to create a free online REST API that you can use whenever you need Pseudo-real data for your e-commerce without running any server-side code.
There are 3 main resources need in e-commerce prototypes:
- All Products: /products/all
- Specific Product: /products/:slug
- Image(s) of the products: /product-images/:slug
One can fetch data with any kind of methods you know(fetch API, Axios, JQuery AJAX, etc.)
fetch("https://edgio-community-ecommerce-api-example-default.layer0-limelight.link/products/all")
.then((res) => res.json())
.then((res) => console.log(res))
fetch("https://edgio-community-ecommerce-api-example-default.layer0-limelight.link/products/next-js-enamel-mug")
.then((res) => res.json())
.then((res) => console.log(res))
fetch("https://edgio-community-ecommerce-api-example-default.layer0-limelight.link/product-images/next-js-enamel-mug")
.then((res) => res.json())
.then((res) => console.log(res))
Use git clone https://github.com/rishi-raj-jain/edgio-commerce-api-example.git
to get the files within this repository onto your local machine.
On the command line, in the project root directory, run the following command:
npm install
node scrape.js && edgio dev
edgio build && edgio run --production
Setting --production runs your app exactly as it will be uploaded to the Edgio cloud using serverless-offline.
Deploying requires an account on Edgio. Sign up here for free. Once you have an account, you can deploy to Edgio by running the following in the root folder of your project:
edgio deploy
See deploying for more information.