クライアントが投稿できるAPIエンドポイントとコメントを取得するAPIエンドポイントを作成しました。コメントの入力と削除APIエンドポイント - Express MongoDB/Mongoose
変更したいコメントのIDと削除する最終エンドポイントを指定することで、クライアントが既存のコメントを更新できるようにする別のAPIエンドポイントを作成しようとしています。これまでに作成したものを次に示します。
var express = require('express');
var router = express.Router();
var Comment = require('../models/comments');
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
/**
* Adds comments to our database */
router.post('/addComment', function(req, res, next) {
// Extract the request body which contains the comments
comment = new Comment(req.body);
comment.save(function (err, savedComment) {
if (err) throw err;
res.json({
"id": savedComment._id
});
});
});
/**
* Returns all comments from our database
*/
router.get('/getComments', function(req, res, next) {
Comment.find({}, function (err, comments) { if (err)
res.send(err); res.json(comments);
}) });
module.exports = router;
あなたの質問はありますか? –
PUTとDELETEエンドポイントはどのように記述しますか? – CodeBananas