javascript 基本休息为express.js创建功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 基本休息为express.js创建功能相关的知识,希望对你有一定的参考价值。


//Basic get Call
app.get('/', (req, res, next) => {
    res.status(200).json({
        message: 'Monica Server started at 4000 port'
    });
});


//Post call using Query Params:

app.post('/addpost', (req, res, next) => {

    if (req.query.title == null || req.query.body == null) {
        res.json({
            message: 'you have to provide title and body query params'
        });
    } else {
        res.send("lala land " + req.query.title);
    }
});


//Post call using URL  Params
app.post('/addpost/:category', (req, res, next) => {

    if (req.params.category == null) {
        res.json({
            message: 'you have to provide category as Url params'
        });
    } else {
        res.send("lala land " + req.params.category);
    }
});


//Post call using Body  json
app.post('/addpost', (req, res, next) => {

    if (req.body.title == null || req.body.desc == null) {
        res.json({
            message: 'you have to provide title and desc as Body json object'
        });
    } else {
        res.send("lala land " + req.body.title);
    }
});



//Update or Put or Patch Rest call
app.put('/post', (req, res, next) => {
    res.json({
        message: {

            action: 'update',
            id: req.query.id
        }
    });
});

//Delete Rest Call
app.delete('/post', (req, res, next) => {
    res.json({
        message: {
            action: 'delete',
            id: req.query.id
        }
    });
});



以上是关于javascript 基本休息为express.js创建功能的主要内容,如果未能解决你的问题,请参考以下文章

如何仅为休息控制器更改基本网址?

text 休息参数,解构数组和对象[JavaScript]

javascript Api网络服务休息

javascript 休息属性

javascript ...休息参数

javascript 传播和休息运营商