美文网首页
Node JS Express Routing

Node JS Express Routing

作者: Zihowe | 来源:发表于2017-07-28 14:54 被阅读9次

    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

    相关文章

      网友评论

          本文标题:Node JS Express Routing

          本文链接:https://www.haomeiwen.com/subject/tfqxlxtx.html