question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
armanbilgecommented, Oct 6, 2022

but query param matchers still use collection.Seq (which can be either mutable or immutable):

See also:

Probably we want Seq to go away.

0reactions
satorgcommented, Oct 6, 2022

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 and Chain won’t match each other anyway 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found