API 서버 만들기

Category
스터디노트 NodeJS
Status
Published
Tags
NodeJS
Study
Description
Published
Slug
notion image
 
 
동물 이름에 따라서 다른 울음소리를 json 데이터로 돌려주도록 할 것임
 
app.get("/sound/:name", (req, res) => { const { name } = req.params //value값을 name으로 한번에 넣어줌 res.json({ 고양이: "야옹야옹" }); //send로 하는 것과 거의 같은데, json으로 명시적으로 적을 수 있음 });
notion image
 
 
이렇게 if문으로 나누면,
요청에서 parameter를 뽑아내서 name에 넣고
name에 따라서 응답
notion image