





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















REST API VS Web Services
Installation
Create project
Install packages npm i mysql2 express npm i D nodemon
Create Server import express from "express" // import ExpressJS framreword const app = express(); // use the expressJS const PORT = process.env.POST || 5000 ; // define PORT app.listen(PORT, () => console.log("Server Open At port: ", PORT));
Create GET request import express from "express" // const app = express(); // use the expressJS const PORT = process.env.POST || 5000 ; // define PORT app.listen(PORT, () => console.log("Server Open At port: ", PORT)); app.get("/", (req, res, next) => { console.log(req.method) res.send("Hello"); // send response }); // create GET request
Work with Routes
Create Routes & Handlers export const getAllProducts = async (req, res) => { return res.send("GET ALL PRODUCTS"); }; import { Router } from "express"; import { getAllProducts } from "../handlers/index.js"; const appRouter = Router(); appRouter.get("/", getAllProducts) export default appRouter;
Time to test
Let’s complete Handlers export const getAllProducts = async (req, res) => { return res.send("GET ALL PRODUCTS"); }; export const getProduct = async (req, res) => {}; export const createProduct = async (req, res) => {}; export const updateProduct = async (req, res) => {}; export const deleteProuct = async (req, res) => {};
V. Working with DB
If you use MAC run mySQL by docker