Routing 就是处理对一个给定URI的HTTP请求, 处理方式一般是借由我们写好的对数据库操作的helper class(data access object)来获取和更新数据。
Routing 就是接受request请求, 进行一些操作,然后返回response, 这个Routing或者controller是唯一一个部分interacts with the model。
Routing
refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path)
and a specific HTTP request method
(GET, POST, and so on).
an example of a very basic route
var express = require('express')
var app = express()
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function (req, res) {
res.send('hello world')
})
// POST method route
app.post('/', function (req, res) {
res.send('POST request to the homepage')
})
For more router practice, see my GitHub inventory and search CS-546 Lab 4
:
https://github.com/HoweZZH/CS546
References:
https://expressjs.com/en/starter/basic-routing.html
https://expressjs.com/en/guide/routing.html
网友评论