Show date: February 6, 2020
50% off during launch: https://purelyfunctional.tv/courses/markdown-editor/
Parse query parameters
URLs can have optional query parameters. They are the key-value pairs that follow the path.
Write a function that takes a URL (represented as a string) and parses out the query parameters into a hashmap.
Notes:
- The query string is the string containing the query parameters. It appears after the ? and before a #. Ex:
https://lispcast.com/search?q=clojure#page2 - The keys and values are URL Encoded. You can use
java.net.URLDecoder/decodeto decode them. - The key-value pairs are separated by
&. Ex:a=1&b=2 - Each key-value pair contains the key, followed by
=, followed by the value. Ex:a=1
Bonus:
Query parameters can contain duplicate keys. Handle them gracefully.