You can fetch parameters from request of client browser using the URL parameters.
http://localhost:3000/api/courses/1
http://localhost:3000/api/courses/1/456
/? query parameters are optional and can be fetched from req.query
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello");
});
app.get("/api/courses", (req, res) => {
res.send([1, 2, 3]); //courses array
});
app.get("/api/courses/:id", (req, res) => {
res.send(req.params.id); //courses array
});
app.get("/api/courses/:id/:value", (req, res) => {
res.send(req.params); //courses array
});
//app.listen(3000, () => console.log("listening"));
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on port ${port}`));
No comments:
Post a Comment