I_Jemin

Handling HTTP Post

const express = require('express');
const app = express();
app.use(express.json());
const courses = [
{ id: 1, name: 'course1'},
{ id: 2, name: 'course2'},
......@@ -27,6 +29,15 @@ app.get('/api/courses/:id',(req,res) => {
res.send(course);
});
app.post('/api/courses',(req,res)=> {
const course = {
id: courses.length + 1,
name: req.body.name
}
courses.push(course);
res.send(course);
});
// PORT
const port = process.env.PORT || 3000;
......