# How to handle extraction of two or more variables within single path segment?

**URL:** <https://softwaremill.community/t/how-to-handle-extraction-of-two-or-more-variables-within-single-path-segment/367>\
**Category:** tapir\
**Created:** [February 19, 2024, 9:23pm UTC](https://softwaremill.community/t/how-to-handle-extraction-of-two-or-more-variables-within-single-path-segment/367 "2024-02-19T21:23:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![limpid-kzonix](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/limpid-kzonix/32/236_2.png) [@limpid-kzonix](https://softwaremill.community/u/limpid-kzonix)\
**Post date:** [February 19, 2024, 9:23pm UTC](https://softwaremill.community/t/how-to-handle-extraction-of-two-or-more-variables-within-single-path-segment/367/1 "2024-02-19T21:23:57Z")

</div>

The issue that I came across is that the input does not support defining advanced use cases of URI matching, such as the following:

- multiple path variables in the same path segment, e.g., `/people/{firstName}-{lastName}/SSN`
- extractor and literal within the same path segment, e.g. `/people/{firstName}-some-literal/SSN` or `/people/some-literal-{firstName}/SSN`

Just for reference: [Micronaut Framework](https://docs.micronaut.io/latest/guide/#routing), Many other frameworks, including Spring, Quarkus, ktor, dotnet, actix-web, implement the URI template specification. But no single scala HTTP library is capable of that.

The expectation is to have something like this:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/softwaremill/original/1X/2d3b6e77ae2850108ca39d7a5d0e08d880e7c925.png)

It seems that it is not possible right now to define a route that will follow Resource Oriented API with custom methods, more details [here](https://cloud.google.com/apis/design/custom_methods)

I would like to know if it is possible to achieve this with tapir. Thanks

---

<div class="post-metadata">

**Author:** ![limpid-kzonix](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/limpid-kzonix/32/236_2.png) [@limpid-kzonix](https://softwaremill.community/u/limpid-kzonix)\
**Post date:** [February 19, 2024, 9:30pm UTC](https://softwaremill.community/t/how-to-handle-extraction-of-two-or-more-variables-within-single-path-segment/367/2 "2024-02-19T21:30:50Z")

</div>

I am particularly interested in the implementation of the API in accordance with the specifications outlined in AIP-136, which can be found at [AIP-136: Custom operations](https://aip-dev.github.io/aip.dev/136).  
The main goal is to guarantee precise documentation, and I’m pleased that Tapir offers this capability. However, does this specific requirement appear to be an edge case?

---

<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:** [February 28, 2024, 11:50am UTC](https://softwaremill.community/t/how-to-handle-extraction-of-two-or-more-variables-within-single-path-segment/367/3 "2024-02-28T11:50:12Z")

</div>

Currently in tapir this is not possible - each path segment is either a capture or a fixed string.

The closest you could get is by mapping over a regular path capture and extracting the values (otherwise - if the value doesn’t match the template - reporting a decode failure). However, this has two downsides:

(1) the OpenAPI spec & docs will show a single path segment, which might have a description, but it’s not the same as separate path params  
(2) you won’t be able to create two endpoints with different templates within a single segment, but otherwise identical

Maybe you could open a GitHub issue? This sounds like a good addition to tapir (since, as you mention, everybody else has it), but wouldn’t be trivial. With an issue we could also see how many other people would like to see the feature added, and prioritise accordingly. Thanks!

---

<div class="post-metadata">

**Author:** ![limpid-kzonix](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/limpid-kzonix/32/236_2.png) [@limpid-kzonix](https://softwaremill.community/u/limpid-kzonix)\
**Post date:** [May 7, 2024, 3:01pm UTC](https://softwaremill.community/t/how-to-handle-extraction-of-two-or-more-variables-within-single-path-segment/367/4 "2024-05-07T15:01:46Z")

</div>

> <https://github.com/softwaremill/tapir/issues/3747>
>
> The details are described here - https://softwaremill.community/t/how-to-handle-…extraction-of-two-or-more-variables-within-single-path-segment/367/1
> 
> 
> - multiple path variables in the same path segment, e.g., /people/{firstName}-{lastName}/SSN
> - path variable and literal within the same path segment, e.g. ,people/{firstName}-some-literal/SSN or /people/some-literal-{firstName}/SSN
> 
> The main objective is to partially support the capabilities described by RFC-6570 URI template spec.
> 
> Many other frameworks, including Micronaut, Spring, Quarkus, ktor, dotnet, actix-web, implement the URI template specification in some way. In the Scala ecosystem, we do not have the support of such things in any framework or library. 
> 
> This limitation prevents users from defining the \[Resource-Oriented API\](https://google.aip.dev/121) (specifically custom methods of \[API-136\](https://google.aip.dev/136)) with good OpenAPI spec
> !\[image\](https://github.com/softwaremill/tapir/assets/8176996/c0847810-1b0f-47ff-b2cb-80b8c3a98308)
> 
> 
> Imagine Tapir becoming the Chuck Norris of Scala routing 😎, leaving all other frameworks in the dust with this killer feature. Plus, it would totally align with the cool kids in other ecosystems 🔥
> 
> 💥 How awesome would that be? 💥
