P
P
Pavel Tkachenko2018-04-11 20:46:08
Node.js
Pavel Tkachenko, 2018-04-11 20:46:08

How to define routes in the CRUD system in Express?

Maybe the question is not well-posed, but the essence is this.
For example, there are routes:

router.route('/')
    .get((req, res) => {
        // Просмотр какого нибудь списка
    })

router.route('/:element')
    .get((req, res) => {
        // Просмотр элемента списка
    })
    .put((req, res) => {
        // Обновление элемента списка
    })
    .delete((req, res) => {
        // Удаление элемента списка
    })

router.route('/add')
    .get((req, res) => {
        // Страница добавление элемента в список
    })
    .post((req, res) => {
        // Добавление элемента в список
    })

How to make it so that it would be possible to indicate that the route is this Update page, the route is this - Delete, etc., etc. ...
In order to get, for example, the following data:
var obj = {
    path : '/',
    create : '/add',
    read : '/:element',
    update : '/:element',
    delete : '/:element'
}

Found various packages for Express in npm but so far only for older versions...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail, 2018-04-16
@mak_ufo

Sounds like you need something higher level. Look towards hapi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question