基本路由
路由是指确定应用程序如何响应客户端对特定端点的请求,该端点是 URI(或路径)和特定的 HTTP 请求方法(GET、POST 等)。
每个路由可以有一个或多个处理函数,当路由匹配时执行。
路由定义采用以下结构:
app.METHOD(PATH, HANDLER)
其中:
app
是express
的一个实例。METHOD
是小写的 HTTP 请求方法。PATH
是服务器上的路径。HANDLER
是路由匹配时执行的函数。
Rb204DAuc6oZJ1mrKptjVOYqhY/S+ZEgbk7aJhhG+CcJNd6Vdwh3jsKVCKzPdGQOA565j5Ud4wJiofGK3/p8M1TGoWNkbSL0+Im+B5GXF9P2f0kQ62NIB+T6qjgwOPkeuoPR2TncPvx51+xXzNyVr//MuvUOz1j4cOG7s+4Fm7fMcg8l0Xd5GL5m1ROjbyIB+/bUn30SmpnNYwGZAyfUaNqxbZwsAjaCrQkSKfJYlYuHdMpaHzY8PRcD6yTHMG1/HfMqVtv/OjE8H2Ho6ub5nI9EeagRhUm1AZQS/w3JLOQh7RUnWSSVr5AZpeKHBDJcDWLm9DUkzvDL6DFTJ7qJBg==
pU0TN7qQOo6BQ35atkLF5RrJEN+fo0hC/+EWxT0+iF5ytMpB3Wvr12Xv6JZd10QE
uAGIqRCvx1w73gzJ2Nxrp/fsOqTCtWWi29V4ETfT2KnTjTye4xrAKdAtirjYgDWn
app.get('/', (req, res) => {
res.send('Hello World!')
})
j3rtE9r/ONpLfhHRKkxbHD50yUfii4FVd5CYfnD+/HsAQ4NCuIqvjgXr/vqXW3WNhgziwgmtRkEOhCP+f6Vb/OBPNhYC+QolcLOr86uuwA8rIVCYpG0Z0Ft6otaeDiuT
app.post('/', (req, res) => {
res.send('Got a POST request')
})
xyv5HV9LrOg76ptl1wVo01dlFOTZVLcXKD0hpi6VmCzeWLqfe5uZTyEf7qssnG9y7YDHhx0llZpncxTjmd9QKw==
app.put('/user', (req, res) => {
res.send('Got a PUT request at /user')
})
xyv5HV9LrOg76ptl1wVo01dlFOTZVLcXKD0hpi6VmCzeMl6f7QQtVwODJa6KwjH5bo6UtNUjc+FyMkREHUjNGA==
app.delete('/user', (req, res) => {
res.send('Got a DELETE request at /user')
})
+aCs44pbFEWsQqWu//b0wYKoRMWC86cFK+ZWRVw6l2EK/Beb5NDbmb0pj4mpFUqs/6axKxjeXwFvyvnnPkiss2cZocYENAuQ0moxwIq2WGFIY9py8M+rV8dTUPnBCMC1kMcbcoqQKybm0xxyf0J+tg==