Query parameters and UrlForm use different underlying collection types
See original GitHub issue…which makes the latter inconvenient for further parsing with QueryParam*Matcher
-s.
Currently UrlForm
uses values: Map[String, Chain[String]]
internally wheres query param matchers expect Map[String, Seq[String]]
. Note, that cats.data.Chain
does not inherit to Seq
.
Ideally it would be nice to have an ability to parse url-encoded forms in this way:
case class MyCoolUrlEncodedForm(foo: Int, bar: String)
object MyCoolUrlEncodedForm {
private object FooMatcher extends QueryParamDecoderMatcher[Int]("foo")
private object BarMatcher extends QueryParamDecoderMatcher[String]("bar")
implicit def entityDecoder[F[_]: Sync]: EntityDecoder[F, MyCoolUrlEncodedForm] =
EntityDecoder[F, UrlForm].map(_.values).flatMapR {
case FooMatcher(foo) +& BarMatcher(bar) =>
DecodeResult.successT(MyCoolUrlEncodedForm(foo, bar))
case _ =>
DecodeResult.failureT(InvalidMessageBodyFailure("invalid form"))
}
}
But currently, instead of just .map(_.values)
it requires .map(_.values.view.mapValues(_.toList).toMap
which is way wordy for such a simple task.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
A Beginner's Guide to URL Parameters - SEMrush
In this comprehensive guide, we explore the ins and outs of URL parameters. Discover now how to use query strings without hurting your ......
Read more >When submitting a GET form, the query string is removed from ...
If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a `?'...
Read more >Use parameters in queries, forms, and reports
By using a form to collect parameters, you gain the following features: The ability to use data-type-specific controls, such as calendar controls for...
Read more >Handling URL Encoded Form Data in Spring REST - Baeldung
Learn how to handle URL encoded form data in Spring REST. ... as this takes care of the basic use cases where data...
Read more >controllers - 1.2.x - Play Framework
Like the HTTP interface, Controllers are procedural and Request/Response ... You can use other Java types than String. ... or even a collection...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
See also:
Probably we want
Seq
to go away.Oh, I see, thank you. But unfortunately simply getting rid of
collection.Seq
in the query param matchers won’t solve the issue. Because apparently,List
andChain
won’t match each other anyway 😃