What does Expressjs urlencoded mean in practice?

Asked

Viewed 4,074 times

3

Analyzing a code built on the Nodejs platform, I came across the instruction express.urlencoded({ extended: false }), to try to understand it, I ended up using the Expressjs documentation, however I could not understand what it means, does and what its importance in the code.

I would be grateful if someone could answer the questions raised in the above text. As well as comment on the relevance of { Extended: false }

1 answer

2


Good night.
The "Extended" option tells the express which library it should use to make the Parsing of the content of the requests it receives.
When Extended : true will use the library Qs and when it is false it will use the library querystring.

The difference between them is that the Qs library allows object nesting (nested Objects), which is pretty much how JSON works:

// {"animal":{"tipo":"cachorro","raca":"vira-lata","idade":3}}

And the querystring library does not support nested Objects.

Source: https://github.com/expressjs/body-parser#bodyparserurlencodedoptions

  • I understood, and what the meaning of express.urlencoded? It is a middleware to handle parameters in the URL?

  • 1

    Actually the middleware is the body-parser, you install it as the express module to give the express the ability to analyze the content of requests before we do some manipulation. (in a nutshell he makes the body content of the requests all cute for us to work easier this data) and urlencoded is a method of that middleware that can receive parameters, as the Extended we speak, other parameters that it accepts you find there in the link I left.

  • @Muriloportugal you explained a lot about the parameter extended but what exactly does the urlencoded ? I know that the express.json() is a parser of information coming from a post request but what urlencoded ? It would be to parse parameters passed in the URL such as "http://site.com/name=Lucas" ?

  • @Jeanextreme002 o urlencoded is a parser of the information coming in the request body. See documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.