채널 생성
const express = require("express");
const app = express();
app.listen(3000);
app.use(express.json());
let channelDb = new Map();
var id = 1;
app
.route("/channels")
// 채널 전체 조회
.get((req, res) => {})
// 채널 생성
.post((req, res) => {
let { channelTitle } = req.body;
if (channelTitle) {
channelDb.set(id++, req.body);
res.status(201).json({
message: `${channelTitle} 채널이 생성되었습니다.`,
});
} else {
res.status(400).json({
message: "요청이 올바르지 않습니다.",
});
}
});
채널 조회
app
.route("/channels/:id")
// 채널 개별 조회
.get((req, res) => {
let { id } = req.params;
id = parseInt(id);
let channel = channelDb.get(id);
if (channel) {
res.json({
channelTitle: channel.channelTitle,
});
} else {
res.status(404).json({
message: "요청이 올바르지 않습니다.",
});
}
})