I’m just looking for some clarification really as I’ve done the challenge.
I’m a bit confused about the part that says “The first and last name parameters should be encoded in a query string e.g. ?first=firstname&last=lastname.”
Where does this happen? The code in the challenge just takes the properties out of the req.query object. Does express turn this into a query string automatically or how does this happen? I don’t get get how it is transformed to the format that is asked for
Hey, first off localhost will only work on your computer youll have to push it to the web with a regular URL which is a whole other issue. Im not sure of the question as it relates to the code but ? is saying to not parse because code=code=something. The names you use here are going to become values not names anymore. Good luck
If you want to know the actual implementation details of the query parsing, will have to look at the source code. The default query parser Express uses is qs.
The server knows the requested URL, so it’s just a matter of parsing it and looking for valid query strings. Using regex or some heuristic for the different parts.
Related
@robheyays You can use localhost for the challenges.
Oh ok. So its the url that is fed into the function which is then parsed and stored in the res.json object, not the other way round?
The thing that got me was the way the it was worded it said:
“The first and last name parameters should be encoded in a query string e.g. ?first=firstname&last=lastname .”
I thought that meant that it was down to me to make sure that that the parameters were encoded into a query string, not that it was the way the query string would be fed into the function
@robhayays - I didn’t quote the code as I has already completed the task with the hint, and just wanted to know how it was implemented as I didn’t understand where the question mark and all the other symbols that turned it into a url came from. I’ve included it in my answer if you still want to have a look at it