In the excellent wreq
Haskell library it is easy to add one or more query parameters to an URL:
opts = defaults & param "key" .~ ["value"]
however what I'm struggling to do is adding a list of parameters at a time:
params = [("key1", "value1"), ("key2", "value2"), ("key3", "value3")]
I know that there is function params
but I could not find any example on how to use it.
Both
param <key>
andparams
are lenses:Without going too much into details, you can think of a lens focusing something, e.g.
param "foo"
focuses on some[Text]
inOptions
that belong to the parameterfoo
(*). You can then change/query/manipulate those values with the correct function (see the lens package).You've already used
(.~)
to replace the current values, and you can use it again withparams
:You can think of
(.~)
in this context as(*) That's not 100% true, since lenses allow you to do all kinds of stuff, but good enough for this context.