The first parameters of get and post are the requested path, the second parameter is the callback function that handles the request, and the callback function has two parameters req and res, which represent the request information and the response information. Path requests and corresponding fetch paths are available in the following ways:
Req.query
Get/search?q=tobi+ferret req.query.q //= "Tobi Ferret" //get/shoes?order=desc&shoe[color]= Blue&shoe[type]=converse req.query.order //= "desc" req.query.shoe.color //= "Blue" Req.query.shoe.type //= "Converse"
Req.body
POST User[name]=tobi&user[email][email protected] req.body.user.name //= "Tobi" Req.body.user.email //= "[email protected]" //POST {"name": "Tobi"} req.body.name //= " Tobi "
Req.params
GET/USER/TJ req.params.name //= "TJ" //Get/file/javascripts/jquery.js req.params[0] / /= "Javascripts/jquery.js" **req.param (name) **//? Name=tobi req.param (' name ') //= = "Tobi" POST name=tobi req.param (' name ') //= = "Tobi" ///user/tobi for/user/:name req.param (' name ') ) //= "Tobi"
Req.query: Handling Get Requests
Req.body:: Processing Post requests
Req.params: Handling get requests in/:xxx form
Req.param (): Can handle get and post requests, but find priority from high to low to Req.params→req.body→req.query
Express parsing HTTP requests