Creating APIs with Serverless Functions by Edgio: A Fake E-Commerce API
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.
Resources
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
How To
One can fetch data with any kind of methods you know(fetch API, Axios, JQuery AJAX, etc.)
Get all products
fetch("https://edgio-community-ecommerce-api-example-default.layer0-limelight.link/products/all")
.then((res) => res.json())
.then((res) => console.log(res))
Get a single product
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))
Get all images of a product
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))
[Contributing] Getting Started
Clone This Repo
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.
Install dependencies
On the command line, in the project root directory, run the following command:
npm install
Run Serverless Functions locally on Edgio
node scrape.js && edgio dev
Testing production build locally with Edgio
edgio build && edgio run --production
Setting --production runs your app exactly as it will be uploaded to the Edgio cloud using serverless-offline.
Deploying to Edgio
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.