# Optional parameter path component

**URL:** <https://forums.swift.org/t/optional-parameter-path-component/86271>\
**Category:** Vapor\
**Created:** [April 27, 2026, 7:48am UTC](https://forums.swift.org/t/optional-parameter-path-component/86271 "2026-04-27T07:48:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon68](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@simon68](https://forums.swift.org/u/simon68)\
**Post date:** [April 27, 2026, 7:48am UTC](https://forums.swift.org/t/optional-parameter-path-component/86271/1 "2026-04-27T07:48:33Z")

</div>

Hi all,

I am trying to apply the tip given at `docs.vapor.codes/basics/routing > Parameters`

 ![Capture d’écran 2026-04-27 à 09.29.25](https://global.discourse-cdn.com/swift/original/3X/0/b/0b17b0ec78e54e25318c712bfd4a18743e10369d.png)

namely to handle the possibility of `nil` for a parameter path component.

However if my route is :

```swift
      wastes.get(":scan", use: self.returnWastes)

```

and the calling http request is:

```swift
  let API_URL: String = "http://127.0.0.1:80/"
    func getWastes() async -> [Waste] {
        let url = URL(string: API_URL + "wastes")!
        var request = URLRequest(url: url)
        request.httpMethod = "GET"
        do {
            let (data, _) = try await URLSession.shared.data(for: request)
            return try JSONDecoder().decode([Waste].self, from: data)
        } catch {
            print("Could not read wastes : \(error)")
            return []
        }
    }

```

The server returns an error.

So how should I formulate the url so that a nil value is read by the server ?

---

<div class="post-metadata">

**Author:** ![ptoffy](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ptoffy/32/44481_2.png) [@ptoffy](https://forums.swift.org/u/ptoffy)\
**Post date:** [April 27, 2026, 8:22am UTC](https://forums.swift.org/t/optional-parameter-path-component/86271/2 "2026-04-27T08:22:55Z")

</div>

Path parameters are typically mandatory because they identify a specific resource. Leaving it out like you do in your client code executes a request to a different endpoint: `/wastes` vs `/wastes/:scan`. You'll need to register both endpoints, the first one to return all resources independently of scan and the second to return one (or a group, related to the scan) in particular.

Otherwise you can also register one endpoint and add the scan ID as query parameter.

FYI we also have a Vapor Discord server at [Vapor](https://discord.gg/rt5W3BsJ)

---

<div class="post-metadata">

**Author:** ![simon68](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@simon68](https://forums.swift.org/u/simon68)\
**Post date:** [April 27, 2026, 8:32am UTC](https://forums.swift.org/t/optional-parameter-path-component/86271/3 "2026-04-27T08:32:36Z")

</div>

Thanks @ptoffy I got it. I simply registered the two routes one with and the other without the parameter and that seems to work. Next time on Discord !
