Wecode - Foundation 1 (부트캠프)/Foundation 1 마무리 퀴즈

Foundation 1- quiz 2 replit

Queen Julia 2023. 9. 5. 20:29

02. CRUD (read)

feed 데이터를 읽을 수 있게 만들어주세요.

feed 임시 데이터를 불러오는 함수는

app.js 상단에서 불러오는 readFeedById, readFeeds 함수를 이용해주세요.

 

// const { readFeedById, readFeeds } = require('./mock-database');

요구 사항

  • feed 에서 하나의 정보와 전체 정보를 읽는 express API를 구현해주세요.
  • feed 상세 정보를 읽는 url은 /feed/:id 로 구성해주세요.

// app.get('/feed/:id', (req, res) => {
  const { id } = req.params; // url 에서 가변 id 가져오기
 // id를 이용하여 하나의 feed를 응답으로 보내주세요.
  console.log(id)
  return res.status(200).json({"feed":readFeedById(id)})
});

  • feed 전체 목록을 읽는 url은 /feeds 로 구성해주세요.

  // 전체 feed를 응답으로 보내주세요.
  return res.status(200).json ({"feeds":readFeeds()})
});

요청, 응답 인터페이스

응답 키 이름이 feed 와 feeds 로 다릅니다. 이 부분 유의해주세요.

 

// feed get 요청

http://localhost:10010/feed/:id

 // 응답

200 {

"feed": {

"id": number,

"author": {

"profileImage": string,

"name": string

},

"title": string,

"contents": string,

"images": string[]

}

}

 

// feed get 요청 (no param)

http://localhost:10010/feeds

 

// 응답

200 {

"feeds": {

"id": number,

"author": {

"profileImage": string,

"name": string

},

"title": string,

"contents": string,

"images": string[]

}[]

}

 


 

좌)를 참고해서 우) 에 쓴 코드


const express = require('express');

const app = express();       

 

 

 

app.listen(8000, function() {console.log('listening on 8000')});  

 

 

이 세 줄은 Node+Express를 고정 ,,