Express encapsulates a variety of HTTP request methods, we mainly use get and post two kinds, namely Qpp.get and Qpp.post. The first parameters of both Qpp.get and Qpp.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 respectively, representing the request information and the response information. Path requests and corresponding fetch paths are available in the following ways:
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"
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
Get/user/tj
req.params.name;//"TJ"
Get/file/javascripts/jquery.js
req.params[j0];//"Javascripts/jquery.js"
? name=tobi
Req.param (' name ');//"Tobi"
POST Name=tobi
Req.param (' name ');//"Tobi"
/user/tobi For/user/:name
Req.param (' name ');//"Tobi"
The above code is not difficult to see the meaning of the following path:
Req.query: Handles a GET request and gets the GET request parameters.
Req.params: Handles a GET or POST request in/:xxx form to get the request parameters.
Req.body: Processing the POST request to obtain the POST request body.
Req.param (): Handles get and post requests, but the lookup priority is from high to low to req.params->req.body->req.query.
Nodejs URL parameter get