Nodejs URL parameter get

Source: Internet
Author: User

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:

    • 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[j0];//"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"
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.