# Multi param query parameters in Tapir

**URL:** <https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388>\
**Category:** tapir\
**Created:** [April 23, 2024, 6:39pm UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388 "2024-04-23T18:39:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SkyAblo2000](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/skyablo2000/32/251_2.png) [@SkyAblo2000](https://softwaremill.community/u/SkyAblo2000)\
**Post date:** [April 23, 2024, 6:39pm UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388/1 "2024-04-23T18:39:38Z")

</div>

Hello, I’m trying to define a Tapir endpoint that has two OptionalMultiQueryParamDecoderMatcher query parameters.

Let’s say one parameter has the name `id` and the other `name`, such that I could call the endpoint with something like:

`GET` `/find?id=1a&id=1b&name=foo&name=bar`

I have a HTTP4S route that works with this using `OptionalMultiQueryParamDecoderMatcher[String]("id")`, which can then be mapped to a `List[String]`

I would really like to do this with Tapir, but I’m having difficulty finding examples or documentation for such a solution ( copilot isn’t helping either 😉 )

Any suggestions?

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [April 23, 2024, 7:30pm UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388/2 "2024-04-23T19:30:33Z")

</div>

Can you try adding an input which decodes to a list, i.e. `query[List[String]]("id")`?

---

<div class="post-metadata">

**Author:** ![SkyAblo2000](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/skyablo2000/32/251_2.png) [@SkyAblo2000](https://softwaremill.community/u/SkyAblo2000)\
**Post date:** [April 23, 2024, 8:30pm UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388/3 "2024-04-23T20:30:10Z")

</div>

Hi @adamw and thanks for the reply. This is what I’ve ended up doing, let me know if this seems wrong:

```scala
val getIdentitiesWithIdentityAndLead: PublicEndpoint[QueryParams, String, List[MyType], Any] =
    endpoint.get
      .in("myEndpoint")
      .in(queryParams)
      .out(jsonBody[List[Identity]])
      .errorOut(jsonBody[String])

```

Then used that with:

```scala
endpoints.getIdentitiesWithIdentityAndLead.serverLogicSuccess { params =>
    val ids = optionalSeqToList(params.getMulti("id"))
    val names = optionalSeqToList(params.getMulti("name"))
    .
    .

```

As a side, `optionalSeqToList` is just:

```scala
def optionalSeqToList[T](seq: Option[Seq[T]]): List[T] = seq.getOrElse(Seq.empty).toList

```

---

<div class="post-metadata">

**Author:** ![SkyAblo2000](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/skyablo2000/32/251_2.png) [@SkyAblo2000](https://softwaremill.community/u/SkyAblo2000)\
**Post date:** [April 23, 2024, 9:50pm UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388/4 "2024-04-23T21:50:14Z")

</div>

That doesn’t appear to work. While the request contains multiple values with the same key, the parameters picked up on the server only sees the last one

---

<div class="post-metadata">

**Author:** ![SkyAblo2000](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/skyablo2000/32/251_2.png) [@SkyAblo2000](https://softwaremill.community/u/SkyAblo2000)\
**Post date:** [April 23, 2024, 10:04pm UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388/5 "2024-04-23T22:04:17Z")

</div>

@adamw your way worked! I just needed to build the Codecs correctly. Thank you!

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [April 24, 2024, 6:53am UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388/6 "2024-04-24T06:53:07Z")

</div>

Oh, what did you have to change in the codecs? For me it simply worked with `query[List[String]]("id")`.

By the way, the approach with `queryParams` would work as well, but the documentation wouldn’t be precise - the `id` parameter wouldn’t get listed there, as the documentation interpreter would have no way of knowing that you’re using such a parameter.

---

<div class="post-metadata">

**Author:** ![SkyAblo2000](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/skyablo2000/32/251_2.png) [@SkyAblo2000](https://softwaremill.community/u/SkyAblo2000)\
**Post date:** [April 24, 2024, 2:18pm UTC](https://softwaremill.community/t/multi-param-query-parameters-in-tapir/388/7 "2024-04-24T14:18:47Z")

</div>

I have an opaque type, so I needed to create some codecs, but once that was done everything worked like a charm.

Thanks again!
