What is the difference between qs and querystring

In body-parser there is a function bodyparser.urlencoded(options) , it has an option with an extension.

The advanced option allows you to choose between parsing URL encoding data with the querystring library (when false) or the qs library (when true). The syntax "advanced" allows you to use rich objects and arrays encoded in URL encoding format, which allows you to use JSON-like experience with URL encoding. See the Qs library for more information.

I read the qs and querystring , but I could not find any obvious difference, so I ask for help here.

+6
source share
1 answer

The extended protocol uses the qs library to parse x-www-form-urlencoded data. The main advantage of qs is that it uses a very powerful serialization / deserialization algorithm that can serialize any json-like data structure.

But web browsers usually do not use this protocol because x-www-form-urlencoded was designed to serialize flat html forms. Although, this can come in handy if you are going to send rich data structures using ajax.

querystring` library provides a basic serialization / deserialization algorithm that is used by all web browsers to serialize form data. This basic algorithm is much simpler than advanced, but limited to flat data structures.

Both algorithms work exactly the same with flat data.

+11
source

Source: https://habr.com/ru/post/983995/


All Articles