now we are working wiht static data only
to learn react or node js
we have to expertise with es6 or arrow functions
app.get("/persons/:id",(req,res,next) =>
{
let idd=req.params.id;
let person=[
{name:"hudere",addr:"vamsi1",id:1},
{name:"hudere",addr:"vamsi2",id:2},
{name:"hudere",addr:"vamsi3",id:3}
];
person=person.filter(x=>x.id==idd);
res.send(person);
}
)
we given code in above
what is this is
whenever we request persons with id like below
http://localhost:3000/persons/1
it will takt that id by request id is params so req.params then id require
it filter id matches with list id
if mathes it shows otherwise not shows
it will show the empty array if not matched with json id which has in code
No comments:
Post a Comment